码迷,mamicode.com
首页 > 其他好文 > 详细

猜数小游戏

时间:2017-08-29 14:15:28      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:between   str   lower   lib   false   pre   std   ios   ==   

 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 }

 

猜数小游戏

标签:between   str   lower   lib   false   pre   std   ios   ==   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!