猜数小游戏
Posted Mr.Struggle
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了猜数小游戏相关的知识,希望对你有一定的参考价值。
1 #include<iostream> 2 #include<stdlib.h> 3 using namespace std; 4 int count = 0; 5 bool judge (int num,int ynum){ 6 if(num == ynum){ 7 cout<<"You got it right in "<<count<<" guesses"<<endl; 8 return true; 9 } 10 11 else if (num>ynum){ 12 cout<<"It`s higher."<<endl; 13 return false; 14 } 15 else{ 16 cout<<"It`s lower."<<endl; 17 return false; 18 } 19 } 20 int main(){ 21 int num = rand()%100+1; 22 int ynum; 23 cout<<"I`m thinking of a number between 1 and 100..."<<endl; 24 bool nether= false; 25 while(!nether){ 26 count++; 27 cout<<"Your guess? "; 28 cin>>ynum; 29 // cout<<endl; 30 nether = judge(num,ynum); 31 32 } 33 }
以上是关于猜数小游戏的主要内容,如果未能解决你的问题,请参考以下文章