#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.