I apologize if the title is too vague, but here is my issue. I've written a program that inputs numbers into a vector and will display it's average and if the student is "passing the class". Everything I have up until now is working just how I need it to.
#include <cmath>
#include <vector>
#include <algorithm>
usingnamespace std;
inlinevoid keep_window_open(){char ch; cin>>ch;}
int main()
{
cout<<"Please enter a score (decimal value) or enter an alpha character to signal you have finished entering your exam scores :";
vector<double>scores;
double score;
while(cin>>score){
cout<<"Please enter a score (decimal value) or enter an alpha character to signal you have finished entering your exam scores :";
scores.push_back(score);
}
double sum = 0;
for(int i=0;i<scores.size();++i) sum +=scores[i];{
cout<<"Your current average is: "<<sum/scores.size()<<'\n';
if((sum/scores.size())<=67.0&&(sum/scores.size())>62.0)
cout<<"You're currently passing the class, but you're close to failing.\n";
elseif((sum/scores.size())>67.1)
cout<<"You're currently passing the class.\n";
elseif((sum/scores.size())<62.0)
cout<<"You're currently not passing the class.\n";
}
system("Pause");
return 0;
}
What I still need to do is to output the score number and how close it is to the average.
Example (it would display like this): "Score 1 is 66.4 which is 12.4356 from your average of 78.8"
How exactly do I 'cout' a number in a vector without knowing how many numbers are in the vector ahead of time.
for (int i = 0; i < scores.size(); ++i)
std::cout << "Score " << i+1 << " is " << scores[i] << " which is " << (sum/scores.size()) - scores[i] << " from your average of " << (sum/scores.size()) << "\n";