我试图让一个程序工作,它会猜测用户正在考虑的数字,但是它目前每次只输出默认的开关动作。请告诉我我做错了什么?谢谢!
srand(time(0));
int lowernum = 1;
int highernum = 1000;
int number=rand()%highernum + lowernum;
string letter = "";
int letternum = 0;
cout<<"\nOkay, think of a number between one and 1000
and I will try to guess it!\n";
cout<<"\nIs your number higher (h), lower (l)
or exactly (e): " << number << "\n";
cin>>letter;
if (letter == "h")
{
letternum = 1;
}
else if (letter == "l")
{
letternum = 2;
}
else if (letter == "e")
{
letternum = 3;
}
switch(letternum){
case'1': highernum = number; cout<<"\nIs your number higher (h),
lower (l) or exactly (e): " << number << "\n"; cin>>letter;
break;
case'2': lowernum = number; cout<<"\nIs your number higher (h),
lower (l) or exactly (e): " << number << "\n"; cin>>letter;
break;
case'3': cout<<"\nWahoooooo! I win! :D\n";
break;
default:cout<<"\nI don't understand what you just typed in.\n";
break;
}