Guess the number game

Hi, this is my first post on this forum so sorry if i did something wrong.
So i made a code, the computer picks a random number between 10 and 3 and u have to guess what is that number.So my program does that, but i want to edit it and make limited tries, with my code the user has infinite tries to guess. Please help.
So here is the code:

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
int a=3;
int b=10;
int c;
int d;
int tries=3;
srand(time(0));
c = rand()%(b-a+1)+a;
cout << "I've got a number between " <<a<<"and"<<b<<endl;
do{
cout<<"Gues the number:";
cin>>d;
if(c==d){
cout<<"well done!"<<endl;
} else{
if(c<d){
cout<<"the number is smaller"<<endl;
}else{
cout<<"the number is greater"<<endl;
}
}
} while
(c!=d);
return 0;
}
If you subtract 1 from tries each time through the loop, then you'll hit the limit when tries == 0. So if you add that to the condition for the while loop, you'll be set.
thank you for replying, but could you show me exactly how to do it, i tried it myself but it wont work, i am an absolute beginner in c++ and programming.
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/general/177011/
http://www.cplusplus.com/forum/general/176750/
Last edited on
Topic archived. No new replies allowed.