forked from dhairyagothi/Cpp-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TASK1_NUMBER_GAME.cpp
42 lines (37 loc) · 1.16 KB
/
TASK1_NUMBER_GAME.cpp
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
40
41
42
#include <iostream>
using namespace std ;
int main() {
string name ;
cout << "________________________________GUESS NUMBER______________________________" << endl ;
cout << " enter your name " << endl ;
cin >> name ;
cout << " Hello " << name << " I thought a number between 0 - 100 . can you please guess it for me " << endl ;
int number ;
int random_number = (rand()% 100) + 1;
int attempts = 0 ;
while (true)
{ attempts++ ;
cout << "\n Guess a number between 0 - 100 "<< endl ;
cin >> number ;
if (number<0 || number >100 )
{
cout << "\n Please enter a number between 0-100 " << endl ;
continue;
}
else if (number > random_number)
{
cout << " \n Wrong guess . your guess is too high " << endl ;
continue;
}
else if (number < random_number)
{
cout<< " \n Wrong guess . your guess is too low " << endl ;
continue;
}
else {
cout << "\n Congratulations! You've guessed the number " << random_number << " correctly in " <<attempts << " attempts." << endl ;
break ;
}
}
return 0;
}