guessing game c 2b 2b

Solutions on MaxInterview for guessing game c 2b 2b by the best coders in the world

showing results for - "guessing game c 2b 2b"
Noemi
11 Jan 2018
1#include <iostream>
2#include <cstdlib>
3#include <ctime>
4using std::cout;
5using std::cin;
6using std::endl;
7
8
9int main() {
10
11    long int randnum,guess,lowerlimit,higherlimit = 0 ;
12    srand(time(NULL));
13
14    do
15    {
16    cout<<"enter your lower limit number: ";
17    cin>> lowerlimit ;
18    cout<<"enter your higher limit number:";
19    cin>>higherlimit;
20    cout<<"enter your guessing number between: " <<"  "<< lowerlimit << " and "<<""<<higherlimit<<" : ";
21    cin>>guess;
22    randnum = rand()%(higherlimit-lowerlimit+1) + lowerlimit ;  
23    // using the conditional operator instead of if / else  
24    if(guess != randnum){
25        cout <<((guess > randnum)? "your guess is large  " : "your guess is too small " ) << "and it is " << guess << " and computer guess is " << randnum << endl;
26
27    }else
28        cout << " GREAT, YOU WON !!!"<<", your guess is " << guess << " and computer guess is " << randnum << endl;
29        
30    }while(guess!=randnum);
31    
32    
33    return 0 ; 
34
35}
36