The code works okay, but if the user input a character instead of a number when asked, the program runs the while structure foreverly, how can i fix this?Code:#include <iostream> #include <iomanip> using namespace std; string oddOrEven(int); int main() { int x; while(1 == 1) { cout<<"Enter a number: "; cin>>x; if(x==0) { cout<<"You've chosen to quit. BYE."<<endl; cin.get(); cin.get(); break; } cout<<"Number is "<<oddOrEven(x)<<endl<<endl; cin.get(); } } string oddOrEven(int n) { return ((n % 2) == 0) ? "even" : "odd"; }
btw, any tips on making the code cleaner are welcome