J
japh
I am on chapter 7 of my C++ text (sigh). Could you help me understand
this? If the user inputs an int, the script works as it should. If
they enter a char instead, it goes into an endless loop. I'm coming
from un-typed languages like PERL and PHP so this makes no sense to me:
(PS - is there a way to preserve indentation in this bulletin board ?)
#include <iostream>
using namespace std;
int main()
{
while(true)
{
int choice;
cout << endl << "Enter a number between 1 - 5: ";
cin >> choice;
if (choice < 1 || choice > 5)
{
cout << endl << "Invalid choice" << endl;
continue;
}
else
{
cout << "You chose " << choice << endl;
}
}// end while
} // end main
this? If the user inputs an int, the script works as it should. If
they enter a char instead, it goes into an endless loop. I'm coming
from un-typed languages like PERL and PHP so this makes no sense to me:
(PS - is there a way to preserve indentation in this bulletin board ?)
#include <iostream>
using namespace std;
int main()
{
while(true)
{
int choice;
cout << endl << "Enter a number between 1 - 5: ";
cin >> choice;
if (choice < 1 || choice > 5)
{
cout << endl << "Invalid choice" << endl;
continue;
}
else
{
cout << "You chose " << choice << endl;
}
}// end while
} // end main