Do while loop

I'm writing a do while loop and I am very confused on what I'm doing. Here is the code I have and I will explain what it should look like after.

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
 cout << "Enter the number of quizzes that have been completed: ";
cin>> numberofquizzes; 

do
{
	
cout << "Enter the grade for Quiz : ";
cin>> val4;

val4 + totquizpts;

(numberofquizzes > 2); //If more than 2 quizzes were taken, ask the user for the sum of the two lowest quiz scores and calculate the maximum possible quiz points using the formula

cout << "Enter the sum of the two lowest quizzes: ";
cin >> val5;	

maxposquizpts = (numberofquizzes - 2)*10; 

(numberofquizzes <= 2); //If 2 or fewer quizzes were taken, set the sum of the two lowest quizzes to 0 and calculate the maximum possible quiz points using the formula

maxposquizpts = numberofquizzes * 10; 

while ()

quizaverage=(totquizpts - val5)/maxposquizpts*100; //Use the sum of the two lowest quiz scores and the maximum possible quiz points to calculate the quiz average using the formula
}


Here is what the outcome should look like:

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

I'm supposed to ask how many quizzes that have been completed then start the loop. Then ask for a quiz score, and add the single quiz score to total points earned. The equations represent other things that need to be in the loop.

I just don't know what to put where. All of the variables are declared.
A couple of things on first glance...

val4 + totquizpts;

Is this supposed to be stored in a variable?


(numberofquizzes > 2);

If you meant this to be an if statement, you're missing some syntax.


1
2
3
4
if (condition)
{
     do stuff;
}

Something to add onto what wildblue said. You don't have a condition in your while statement. If your loop does run, it will only run once. If you want it to run based on how many quizzes are selected, you might need to have a condition like this:

1
2
3
4
5
6
7
8
int i=0;

do{
//loop info

i++; //adds 1 to i after each loop iteration so it won't be infinite
}
while(i<numberofquizzes); //will loop based on how many quizzes user selected. 

Yes I think I do need an if, but I have multiple if statements I need to put in if it looks like. How would I go about doing that?

For example

1
2
3
4
5
6
7
if (numberofquizzes > 2)
cout << "Enter the sum of the two lowest quizzes";
cin >> val5;

if (numberofquizzes <= 2)
val5=0;
maxposquizpts=numberofquizzes*10;


It doesn't seem like I would be able to write two if statements one after another.

val4+totquizpts is supposed to add a single quiz score to the total quiz points earned.

If you want multiple statements to be performed in an if (or for/while etc), use braces.

1
2
3
4
{
do stuff 1
do stuff 2
}



Last edited on
Thanks for the help, appreciate it.
One last quick thing I can't seem to figure out. When I run the program and it asks how many quizzes I took, I enter let's say 9, and it ask for 8 grades and then it counts the 9th quiz as entering the two lowest quiz scores together. Any idea why?

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
cout << "\nEnter the number of quizzes that have been completed: ";
cin >> numberofquizzes;

do
{
cout << "Enter the grade for Quiz " << x << ": ";
cin>> val4;

val4 + totquizpts;

if (numberofquizzes > 2)

maxposquizpts = (numberofquizzes - 2)*10;

(numberofquizzes <= 2);
maxposquizpts = numberofquizzes * 10;

quizaverage=(totquizpts - val5)/maxposquizpts*100;

x++;
}
while (x<numberofquizzes);

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


There must be one little detail I need to change to make it so it displays 9 quizzes when I say I have took 9 quizzes. (Instead of displaying 8 quizzes and counting the "Enter the sum of the two lowest quizzes" as the 9th quiz)
Thank you in advance.
What value does x start out with?

If x starts at 1, then change line 22 to while (x <= numberofquizzes);.
Yep you are right, I feel like a doofus, thank you.
Topic archived. No new replies allowed.