C++ 我怎样才能让玩家再次玩猜谜游戏? #包括 #包括 #包括 使用名称空间std; int main() { 智力猜测; srand(时间(空)); 整数=兰德()%10+1; 做 { cout
是的,您可以将这些都放在另一个do while循环中。在循环中,首先执行此循环,然后要求用户输入“y”或“n”(或您喜欢的任何标识符),并将其存储到char变量中。然后只需检查他们输入的内容是否等于外部循环while部分的“y”C++ 我怎样才能让玩家再次玩猜谜游戏? #包括 #包括 #包括 使用名称空间std; int main() { 智力猜测; srand(时间(空)); 整数=兰德()%10+1; 做 { cout,c++,C++,是的,您可以将这些都放在另一个do while循环中。在循环中,首先执行此循环,然后要求用户输入“y”或“n”(或您喜欢的任何标识符),并将其存储到char变量中。然后只需检查他们输入的内容是否等于外部循环while部分的“y” 请注意,如果使用此方法输入“是”,游戏将停止,因此您可能希望使用sting变量,并检查更多可能的输入。“[…]让用户尽可能多地玩此游戏,只要他/她不喜欢”Whaaa?我必须做一些嵌套的do…while语句在主do…while:是的!对不起…可能是打字错误…谢谢你指出 #
请注意,如果使用此方法输入“是”,游戏将停止,因此您可能希望使用sting变量,并检查更多可能的输入。“[…]让用户尽可能多地玩此游戏,只要他/她不喜欢”Whaaa?我必须做一些嵌套的do…while语句在主do…while:是的!对不起…可能是打字错误…谢谢你指出
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
int guess;
srand(time(NULL));
int number=rand()%10+1;
do
{
cout<<"Welcome to the number guessing game!"<<endl;
cout<<"Guess a number between 1 and 10"<<endl;
cin>>guess;
if(guess<number)
cout<<"Your guess is less than the number "<<endl;
else if(guess>number)
cout<<"Your guess is greater than the number "<<endl;
if(guess==number)
cout<<"Congratulation! You guess the number!!"<<endl;
}
while(guess!=number);
system("PAUSE");
return 0;
}