Guess the number game homework

So my homework is to edit this code. I need to make it so that the player can have limited tries for ex. the player can only have 3 tries, if he fails the game finishes. But in this code one has unlimited tries, so if someone has the time can you please edit my code and help me i am a total beginner in programming and i am stuck on this code for days. 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;
}
closed account (48T7M4Gy)
Please use code blocks from the format toolbox on the right <>

At the moment all our mind readers are busy on other projects so it would be a great idea if you would do the format thing, but also tell us what your program is doing that isn't what you want and why.

Sample output or full error list with line numbers makes it so much easier.

PS if your homework is to actually edit the code which was given to you are actually then in the paid consulting regime not free advice and assistance.
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/general/176750/
http://www.cplusplus.com/forum/beginner/176897/ and others
Last edited on
closed account (1vD3vCM9)
And listen, we don't do your homework. It's YOUR mission to learn at class, although we will be happy to help.
Topic archived. No new replies allowed.