Calculating the Average/Max/Min of the 5 grades.

Assignment: You are to create one variable to keep track of five grades which will be input by the user. You should also have another variable which calculates and holds the sum of these five grades, and an average/max/min variable each to hold the average/max/min of the five grades.

*******When I run the program, it comes out like so:
Enter a number: 5
enter a number: enter a number: enter a number: enter a number:
*******I checked the code and I don't know how to fix it.

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<iostream>

using namespace std;

int main()
{
  
 double sum, max, min, avg;
 double number;
 int N=5; //N is the number to be inpute
  cout << "\nEnter a number: ";
  cin >> number;
  sum = number;
  max = number;
  min = number;
for (int i = 2; i <= N; i++)      //loop
{
    cout<<"enter a number: ";
  sum = sum + number;
  if (max < number) max = number;
  if (min > number) min = number;
  
} // end of loop
  avg = sum/N; //display the results sum, max...
  cout <<"\nsum is:" << sum <<"\nmax is:" << max;
  cout <<"\nmin is:" << min;
  cout<< "\naverage is:" << avg;

}
How many times do you show "Enter a number" in the code? On which lines?

How many times do you read input in the code? On which lines?
Topic archived. No new replies allowed.