After the first question is asked "How many books have you read in the past year?" if I enter characters "faslkdfja" or any other combination of course, it throws me into an infinite loop... help!?
Here it is:
Yay!!... not... Help please! lolCode:#include <iostream> using namespace std; int main() { int books; char book; char input; char choice; while( choice != 'Y' ) { cout<<"How many books have you read this last year?\n"; cin>> books; cin.ignore(); cout<<"You read "<< books <<"?\n"; if ( books >= 90 ) { cout<<"Listed below are your options:\n"; cout<<" a : 42' Tv Set!\n"; cout<<" b : MP3 Player!\n"; cout<<" c : Sony Cd Player!\n"; cout<<" d : Book Subscription!\n"; cout<<" e : A peice of Candy!\n"; cin>> input; cin.ignore(); if ( input == 'a' ) { cout<<"Wow! Congratulations! You've won a 42' Tv Set!\n"; cin.get(); } else if ( input == 'b' ) { cout<<"Good Job! You've won an MP3 player!\n"; cin.get(); } else if ( input == 'c' ) { cout<<"The work paid off! You've won a Sony CD player!\n"; cin.get(); } else if ( input == 'd' ) { cout<<"This'll help you boost your score! Your very own National Book Club Subscription!\n"; cin.get(); } else if ( input == 'e' ) { cout<<"Here is some candy, maybe it will boost your brain power!\n"; cin.get(); } else if ( input != 'a' || input != 'b' || input != 'c' || input != 'd' || input != 'e' ) { cout<<"Error. Please enter a, b, c, d, or e\n"; } cout<<"Hint: Press enter\n"; cin.get(); } else if ( books >= 75 ) { cout<<"Listed below are your options:\n"; cout<<" b : MP3 Player!\n"; cout<<" c : Sony Cd Player!\n"; cout<<" d : Book Subscription!\n"; cout<<" e : A peice of Candy!\n"; cin>> input; cin.ignore (); if ( input == 'b' ) { cout<<"Good Job! You've won an MP3 player!\n"; cin.get(); } else if ( input == 'c' ) { cout<<"The work paid off! You've won a Sony CD player!\n"; cin.get(); } else if ( input == 'd' ) { cout<<"This'll help you boost your score! Your very own National Book Club Subscription!\n"; cin.get(); } else if ( input == 'e' ) { cout<<"Here is some candy, maybe it will boost your brain power!\n"; cin.ignore(); } else if ( input != 'b' || input != 'c' || input != 'd' || input != 'e' ) { cout<<"Error. Please enter a, b, c, d, or e\n"; cin.get(); } cout<<"Hint: Press enter\n"; cin.get(); } else if ( books >= 50 ) { cout<<"Listed below are your options:\n"; cout<<" c : Sony Cd Player!\n"; cout<<" d : Book Subscription!\n"; cout<<" e : A peice of Candy!\n"; cin>> input; cin.ignore(); if ( input == 'c' ) { cout<<"The work paid off! You've won a Sony CD player!\n"; cin.get(); } else if ( input == 'd' ) { cout<<"This'll help you boost your score! Your very own National Book Club Subscription!\n"; cin.get(); } else if ( input == 'e' ) { cout<<"Here is some candy, maybe it will boost your brain power!\n"; cin.ignore(); } else if ( input != 'c' || input != 'd' || input != 'e' ) { cout<<"Error. Please enter a, b, c, d, or e\n"; cin.get(); } cout<<"Hint: Press enter\n"; cin.get(); } else if ( books >= 25 ) { cout<<"Listed below are your options:\n"; cout<<" d : Book Subscription!\n"; cout<<" e : A peice of Candy!\n"; cin>> input; cin.ignore(); if ( input == 'd' ) { cout<<"This'll help you boost your score! Your very own National Book Club Subscription!\n"; cin.ignore(); } else if ( input == 'e' ) { cout<<"Here is some candy, maybe it will boost your brain power!\n"; cin.ignore(); } else if ( input != 'd' || input != 'e' ) { cout<<"Error. Please enter a, b, c, d, or e\n"; cin.get(); } cout<<"Hint: Press enter\n"; cin.get(); } else if ( books >= 1 ) { cout<<"Listed below are your options:\n"; cout<<" e : A peice of Candy!\n"; cin>> input; cin.ignore(); if ( input == 'e' ) { cout<<"Here is some candy, maybe it will boost your brain power!\n"; cin.get(); } else if ( input != 'e' ) { cout<<"Error. Please enter your only option next time, e\n"; cin.get(); } else if ( books == 0 ) { cout<<"Listed below are your options:\n"; cout<<"Sorry, Start reading and maybe you'll win something next time!\n"; } else if ( books < 0 ) { cout<<"Error. Please enter a positive integer.\n"; cin.get(); } } if ( books == book ) { cout<<"Oops! Please inter a positive integer!\n"; cin.get(); } cout<<"Quit? Y/N\n"; cin>> choice; if ( choice == 'Y' ) { break; } } return 0; }



LinkBack URL
About LinkBacks



