I'm new in C++ language programing and I thought to start to make some simple projects. I saw on internet a program to guess a number.If you don't guess the number, the program will say to decrease or increase the number. After you make the program, to complicate it you need to end the program after 10 attempts with the message "You are more patience than me. You won!"
How can i write the program to say that after 10 attempts?
P.S. I wrote some code .
#include <iostream>
usingnamespace std;
int main()
{
int a;
cout<<"a=";
cin>>a;
while (a>5)
{
cout<<"You need to decrease ";
cin>>a;
while (a<5)
{
cout<<"You need to increase ";
cin>>a;
}
}
while (a<5)
{
cout<<"You need to increase ";
cin>>a;
while (a>5)
{
cout<<"You need to decrease ";
cin>>a;
}
}
if (a==5)
{
cout<<"You won!";
}
}
#include <iostream>
usingnamespace std;
int main()
{
int no_of_attempts = 0;
int guess = 0;
int hidden_no = 37;
while (cout << "Make a guess: " && cin >> guess && no_of_attempts < 10)
{
if(guess > hidden_no)
cout<<"You need to decrease\n";
elseif( guess < hidden_no)
cout<<"You need to increase\n";
else
cout <<"You guessed correctly\n";
no_of_attempts++;
}
cout << "You ran out of chances, but I am told to tell you \"You are more patience than me. You won!\"\n";
return 0;
}