首页 > 其他 > 详细

猜数小游戏

时间:2017-08-29 14:01:22      阅读:259      评论:0      收藏:0      [点我收藏+]
 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 }

 

猜数小游戏

原文:http://www.cnblogs.com/lvcoding/p/7447640.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!