Noob problem...

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 .


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  #include <iostream>

using namespace 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!";
   }
}
Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>

using namespace 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";
           
        else if( 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;
}
Thank you.
Last edited on
closed account (48T7M4Gy)
I'll tie a string around my finger to ensure it doesn't happen again.
Topic archived. No new replies allowed.