#include <iostream>
#include<stdlib.h>
#include <string>
//调试f10执行下一步,f11执行下一句
using namespace std;
int main ()
{
cout << "game start:" << endl;
cout << "please input a number between 0-100: " << endl;
int play_again = 1;
int true_num= 0, guess_num = 0;
int flag = 1;
string user_choise;
string y = "y";
string Y = "Y";
string n = "n";
string N = "N";
while(1)
{
if (play_again == 1 && (true_num == guess_num) )//再玩一次程序
{
true_num = rand()%(101); //产生一个随机数
cout << "please input your guessing number: " << endl;
cin >> guess_num; //用户猜测
}
if ((guess_num != true_num)&& (flag !=1))//多次猜测
{
cin >> guess_num;
}
if(guess_num != true_num)//猜错了
{
if (guess_num > true_num )
{
cout << "the true num is smaller " <<endl;
flag ++;
}
if (guess_num < true_num)
{
cout << "the true num is bigger " <<endl;
flag ++;
}
}
if (guess_num == true_num)//猜对了
{
cout << "Guess right !" <<"Do u want to play again? please input 'Y' or 'N' " << endl;
cin >> user_choise;
if ((user_choise == y) || (user_choise == Y) )
{
play_again = 1;
flag = 1;
}
if ((user_choise == n) || (user_choise == N) )
{
play_again = 0;
flag = 1;
break;
}
}
}
system("pause");
return 0;
}