Problems with loop

I'm having problems with this loop. I'm making a grading program and I'm trying to make the loop repeat when a negative value is entered.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 if (choice == 1);
        {
            cout << "Enter current total of points for Homework, Labs, Quizzes\n";
            cin >> user_scores_HLQ;

                while (user_scores_HLQ < 0);
                {
                    cout << "Please enter a valid positive value.\n";
                }
                if (user_scores_HLQ > 0);
                {
                    cout << "Enter total possible points for Homework, Labs, Quizzes\n";
                    cin >> possible_HLQ;
                }
                while (possible_HLQ < 0);
                {
                    cout << "Please enter a valid positive value.\n";
                }
        }


Any suggestions?
There's no way I can say anything without practically doing it myself, so I'll just go ahead and type it up for you. It will be faster and you'll get to see how it's done.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cout << "Enter current total of points for Homework, Labs, Quizzes\n";
while (1){
	cin >> user_scores_HLQ;
	if (user_scores_HLQ >= 0)
		break;
	else
		cout << "Please enter a valid positive value."<<endl;
}
cout << "Enter total possible points for Homework, Labs, Quizzes"<<endl;
while (1){
	cin >> possible_HLQ;
	if (possible_HLQ >= 0)
		break;
	else
		cout << "Please enter a valid positive value."<<endl;
}

break passes control to the line just after the innermost loop (it "breaks" the loop).
Thanks. But whats the (1) stand for? Does it make the while only apply to choice 1?
it means true. you can replace the 1 with the keyword true. the point is it will do it forever.
Yeah, you can use true if you fear they might some day change its meaning to zero.
Thanks a lot. I appreciate it, that loop was killing me.
Last edited on
Topic archived. No new replies allowed.