Ok so my class is being taught experimentally where my class is group work, and the other class regular lectures. The program at hand is going to accept as input the names of students. Then the grades of students. Then calculate the average grade. I need help setting my loop to only ask for grades 10 times. What exactly is the syntax here? The program isn't finished yet.
Thanks. I'm going to try this. I'm confused about i though. is i just a loop counter? Does that variable need to be returned? Ugh so confused. THis class is being taught differently and while I have some experience with Java i'm finding c++ kind of strange.
for (sum=10000;testScores=0; testScores++)
{ cout<<"Enters test scores"<<endl;
cin >> testScores;
sum=0+testScores;
}
The first term of the for statement initializes the loop counter, in this case you're setting sum to 10000. The second term of the for statement is the continuation condition. The loop will continue as long as the condition is true. In this case, you will assign 0 to testScores, then test if that is true (0 is false), so it will terminate the loop. You never get to the third term of the for statement which is the step. You don't want to increment testScores.
Lendradwi showed you the three loop forms. The for loop is most commonly used when you want to execute the loop a fixed number of times.
1 2 3 4 5 6
sum = 0;
for (int i=0; i<10; i++)
{ cout<<"Enters test score"<<endl;
cin >> testScore;
sum += testScore;
}