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";
}
}
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).