Problem with for loop

Hi, the problem with my code is that, the for loop gets the average but then it adds that average to another average and so forth. So, the first student gets the correct average but then the following student gets an average but his/her average gets added with the previous average.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

			  for (int x=0;x<5;x++)//this is where i'm having probelms
			  {
				  totalaverage=totalaverage+TestScores[x];
				  
			  }
			
		            total=totalaverage/5;
		            cout<<total<<endl;
		   }
		         
		        
		  

	return 0;
    system ("pause");
}
Last edited on
You need to reset the running total to 0 each time you start processing a new student.
line 20 has issues... its missing an open brace and if i=0, how can i be less than 0?
So do I have to add another for loop to reset the total to zero?
I'm sorry for asking, I'm still beginning to code
no.
You just have to put

total = 0;
asking questions is good way to get answers.
thank you guys it worked!! with the total=0
Last edited on
Topic archived. No new replies allowed.