Grading Program infinite loop.

#include <iostream>
#include <string>
#include <time.h>
#include <algorithm>
int main(){

std::cout << "Click a to start,b to exit.";
char aOr;

std::cin >> aOr;
while (aOr != 'b'){
std::cout << "Enter your grade.";
int grade;
std::cin >> grade;
if (grade <= 100 && grade >= 90){
std::cout << "You got an 'A'";
}
else if (grade <= 89 && grade >= 80){
std::cout << "You got a 'B'";
}
else if (grade <= 79 && grade >= 70){
std::cout << "You got a 'C'";
}
else if (grade <= 69 && grade >= 60){
std::cout << "You got a 'D'";
}
else if (grade <= 59 && grade >= 0){
std::cout << "You got an 'F'";

}
else{
std::cout << "Invalid Input.";
}



}

}

When I write an invalid input, it goes into an infinite loop , and I can't figure out why, please help.
At the end of the while loop you need to ask to continue or quit otherwise the condition while (aOr != 'b') will not be changed.
This is because, the value of aOr is never equal to'b'. So, you have an nfinite loop.

To solve your problem, do this:
1
2
3
4
else{
 std::cout << "Invalid Input.";
aOr=b;
 }


I am assuming, that you want to end your program as soon as the user enters an invalid choice.
Topic archived. No new replies allowed.