How to display vectors without a definite number

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
inline void 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";
                        
            else if((sum/scores.size())>67.1)
                 cout<<"You're currently passing the class.\n";
            else if((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.
Can you try a for loop?
1
2
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";


This would do it for every value in the array.
That...was awesome, thank you.

Works perfectly! ^.^
Topic archived. No new replies allowed.