1 2 3 4 5 6 7 8 9 10
|
cout << "Please enter the first score for student #" << counter << ".\n";
cin >> score1;
cout << "Please enter the second score for student #" << counter << ".\n";
cin >> score2;
cout << "Please enter the third score for student #" << counter << ".\n";
cin >> score3;
cout << "Please enter the fourth score for student #" << counter << ".\n";
cin >> score4;
cout << "Please enter the fifth score for student #" << counter << ".\n";
cin >> score5;
|
stuff like this you want to use an array and a for loop.
this can be rewrote as:
1 2 3 4 5 6 7 8
|
void scores()
{
for( int i = 0; i < scores; ++i ) //in this case scores == 5
{
cout << "Please enter score" << i + 1 <<" for student #" << counter << ".\n";
cin >> score[i];
}
}
|
also generally speaking you want to avoid using global variables and instead pass them to the function.
I see some other problems too:
1 2
|
double studTotal = score1 + score2 + score3 + score4 + score5,
double studAverage = studTotal / 5, classAverage = studAverage / counter;
|
You are trying to do stuff with undefined variables. Think about this math problem:
A = B + C What is A? We do not know since we don't have values for B and C yet.
I would also suggest indenting inside of each set of {braces}.
As far as average scores. You can add them up and divide by how many scores there were.
I would recommend using class/struct to organize.
1 2 3 4 5 6 7 8 9 10 11
|
struct Student
{
static constexpr int NumberOfScores = 5;
//or if You want I think this compiles in c++11 ----
// const int NumberOfScores = 5;
// I would also make this a private data member
double Scores[NumberOfScores];
double AverageScore;
int ID;
std::string Firstname , Lastname;
};
|
Then we can create a student like:
Or an array if you wish to save all the information.
To call the member variables you will do
fred.FirstName = "Fred";
ect...