Hello I am trying to teach myself C++ at night and I have started by writing things that are enjoyable such as basic games. I have come to a problem that for user input in choices i usually use a menu such as
I know I was lazy and didn't require the user to re-choose if they choose above 3 I just had the last option choose to adventure regardless.Code:void town()
{
hp = level * 10;
int move;
cout<<"You are in town. You have "<<gold<<" gold and "<<attack<<" attack power.\n";
cout<<"Would you like to\n";
cout<<"1. Buy Weapons\n";
cout<<"2. Buy Spells\n";
cout<<"3. Adventure\n";
cin>>move;
if (move == 1)
{
buyweapons();
}
else if (move == 2)
{
buyspells();
}
else
{
adventure();
}
}
My question is why can I not find a way around the entire game glitching if the user inputs a char or string of characters. I have tried to devise a way around it but after the glitch happens it seems to only register the next line of code and continually display it. Is there maybe a nuetral variable type I can have cin? Then through an if statement convert to either a char or int?
I am sorry if this question has already been answered, but I couldn't find it by searching.