#include <iostream>
#include <vector>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
using namespace std;
void determine_grade (double &, char & );
double calc_average (vector <double> averagevector);
double find_highest (vector <double> highestvector);
double find_lowest (vector <double> lowestvector);
int main ()
{
double average = 0.00;
double highest = 0.00;
double lowest = 0.00;
double input;
char letter;
double score = 0;
vector <double> vecinput(0);
for (int i = 0; i < vecinput.size(); i++)
{
cout << " Enter result " << vecinput[i] << "(or -1 if no more result):";
cin >> input;
vecinput[i] = input;
if (input < 0 || input > 100)
{
cout << " Invalid Input";
}
else(input == -1);
{
break;
}
}
determine_grade(score, letter);
cout << " Summary of the Results:" << endl;
cout << " Result" << vecinput.size()<<
cout << setprecision(2) << fixed << score << "Grade" << letter << "\n";
average = calc_average(vecinput);
cout << " The average of the results =" << setprecision (2) << fixed << average << "\n";
lowest = find_lowest(vecinput);
cout << " The lowest of the results =" << setprecision (2)<< fixed << lowest << "\n";
highest = find_highest(vecinput);
cout << " The highest of the results =" << setprecision (2) << fixed << highest << "\n";
system ("Pause");
return 0;
}
double calc_average(vector <double> averagevector) // This function will find the average off the results.
{
double total = 0.00;
double average = 0.00;
for (int i = 0; i < averagevector.size(); ++i)
{
total += averagevector[i];
}
average = (double) total / averagevector.size();
return average;
}
double find_highest (vector <double> highestvector) // This function will find the higest grade of the results.
{
double max= 0.00;
max = *max_element(highestvector.begin(),highestvector.end());
return max;
}
double find_lowest (vector <double> lowestvector) // This function will find the lowest grade of the results.
{
double min = 0.00;
min = *min_element(lowestvector.begin(),lowestvector.end());
return min;
}
void determine_grade (double &num, char &grade)
{
if (num >= 90 && num <= 100)
grade = 'A';
else if (num >= 70 && num <= 89)
grade = 'B';
else if (num >= 60 && num <= 69 )
grade = 'C';
else if (num >= 50 && num <= 59)
grade = 'P';
else
grade = 'U';
}
最高、最低の成績を表示するプログラムを作成しようとしています。平均と文字のグレードも表示する必要があります。ベクトル添字が範囲外エラーになっています。このプログラムを実行しようとするたびに、932 行に表示されます。何を間違えたのかわかりません。
今、ベクトル反復子が微分可能ではないというエラーが発生しています