For/ do while loop touble

I'm having trouble writing a for loop. I'm trying to code something like this :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
float val1, val2, val3;
int maxpts, totppts, i, numberofprograms;
	
	
cout << "Enter the number of programs that have been completed: ";
cin >> numberofprograms;

for (i=0; i <= numberofprograms; i++)	
{

cout << "Enter the grade for Program ";    
cin >> val2;


cout << "Enter the maximum possible points for Program ";        
cin >> val3;


val2 + totppts;
val3 + totppts;
}	 



The code runs, but I want it to add a number after program. So when I ask how many programs have been completed and it will run the loop that many times. It should resemble this :

Enter the number of programs that have been completed: 3

Enter the grade for Program 1: 49
Enter the maximum possible points for Program 1: 50

Enter the grade for Program 2: 73
Enter the maximum possible points for Program 2: 75

Enter the grade for Program 3: 96
Enter the maximum possible points for Program 3: 100

**Also came across another problem while doing a do while loop. It seems similar to the part before but is is in a do while loop so I'm a little confused.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cout << "\nEnter the number of quizzes that have been completed: ";
cin >> numberofquizzes;

do
{

(i=1; i <= numberofquizzes; i++)

cout << "\nEnter the grade for Quiz ";
cin >> val4;


cout << "\nEnter the sum of the two lowest quizzes";	
cin >> val5;

while


This is how it should look printed out :

Enter the number of quizzes that have been completed: 3

Enter the grade for Quiz 1: 10
Enter the grade for Quiz 2: 10
Enter the grade for Quiz 3: 9

Enter the sum of the two lowest quizzes: 19

So it is very similar to the for loop but I don't know what goes where.
I'm supposed to take the two lowest quiz scores and add them up. Is that what I would put in the while statement? and then everything else is under do?

Last edited on
8
9
10
11
12
13
14
15
16
17
18
19
for (i=1; i <= numberofprograms; i++) // Start at 1
{
    cout << "Enter the grade for Program " << i << ": "; // You can still use 'i' within the loop
    cin >> val2;

    cout << "Enter the maximum possible points for Program " << i << ": ";
    cin >> val3;

    // These two statements don't do anything (and totppts is uninitialized anyways)
    val2 + totppts;
    val3 + totppts;
}
Last edited on
Thanks, yeah those two equations I need to use for something else in the program but are needed to be in the the body of the loop. Supposed to add points earned to total program points earned and add max points to the total program points.

**Having trouble with do while loop now.
Last edited on
Topic archived. No new replies allowed.