1. 程式人生 > >猜數小遊戲

猜數小遊戲

return turn == std clas rand col iostream using

 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 }

猜數小遊戲