while if loop

I am trying to write a stop command if the number of test is 0. I tried a if else statement and it doesn't print the statement and end the program, it tries to calculate 0 tests.

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
int main()
{
    int number; //number of tests
    int countNumber; //couter of test scores
    float test; //test scores
    float totalTest; //Total of test scores
    float testAve; //Test average
    
    // Get the total number of tests.
    cout<<"Enter the total number of tests taken: ";
    cin>>number;
    countNumber=0;
    totalTest=0;
    while (number>countNumber)
    {
          cout<<"Test score: ";
          cin>>test;
          totalTest=totalTest+test;
          cout<<"The total of the test scores are: "<<totalTest<<endl;
          countNumber=countNumber+1;
          testAve=totalTest/countNumber;
    }       
    cout<<"The average test score is: "<<testAve<<endl;

    system ("pause");

return 0;
}
Last edited on
Topic archived. No new replies allowed.