猜数字游戏
#include<iostream>
#include<string>
#include<time.h>
using namespace std;
int main()
{
cout<<"Guess number"<<endl;
srand((int)time(0));
int number=rand()%10+1;
bool isSuccess=false;
for(int i=0;i<5;i++){
cout<<"I am thinking a number between 1-10,could you guess this number?You guess what:";
int numberGuess;
cin>>numberGuess;
if(numberGuess>number){
cout<<"It is larger than the number."<<endl;
}
else if(numberGuess==numbr){
isSucess=true;
cout<<"Congratulations,you are right!"<<endl;
break;
}
else{
cout<<"It is smaller than the number."<<endl;
}
}
if(isSucess){
}
else{
cout<<"You failed";
}
return 0;
}