CPP Primer Plus Chapter 7 exercise 2:
requires the user to enter up to 10 golf products and store them in an array. The program allows the user to finish typing early, display all scores on one line, and then report the GPA. Please use 3 array processing functions to input, display, and calculate the average score.
problem description:
Why can, enterScore () return a float value when entering 10 float? Using Visual Studio"s debugger, I looked through the execution of the program one by one, and found that when I entered the last value, the return statement was not executed. What is the situation of the great god?
here is my code:
-sharpinclude <iostream>
using namespace std;
const int SIZE = 10;
int enterScore(float score[], const int SIZE);
float calculateScore(const float score[], const int SIZE);
void displayScore(const float score[], const int SIZE, float average);
int main()
{
float score[SIZE];
int count;
float average;
count = enterScore(score, SIZE);
average = calculateScore(score, count);
displayScore(score, count, average);
return 0;
}
int enterScore(float score[], const int SIZE)
{
cout << "Enter the scores in this match (q to quit): \n";
for (int count = 0; count < SIZE; countPP)
{
cout << "Score " << count + 1 << ": ";
if (!(cin >> score[count]))
return count;
}
}
float calculateScore(const float score[], const int SIZE)
{
float total = 0.0f;
for (int count = 0; count < SIZE; countPP)
total += score[count];
return total / SIZE;
}
void displayScore(const float score[], const int SIZE, float average)
{
cout << "There are scores and average.\n"
<< "Scores: ";
for (int count = 0; count < SIZE; countPP)
cout << score[count] << " ";
cout << "\nAverage: " << average << endl;
}