Guess the number game

Hello everyone.
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;

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;
}
You need two more variables, I suggest more meaningful names such as "attempts" and "max_attempts". These should be numbers, technically speaking unsigned would be appropriate since neither one can ever be negative but a plain integer would be fine; don't forget to initialize them. The flow of your program is controlled by the conditional test on Line 27. You combine multiple conditional tests by using the Logical Operators: ( http://en.cppreference.com/w/cpp/language/operator_logical#results ). Hit us back if you need more help.
closed account (48T7M4Gy)
Please don't triple post

http://www.cplusplus.com/forum/general/177011/
http://www.cplusplus.com/forum/general/176750/
Topic archived. No new replies allowed.