-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTASK1.cpp
More file actions
41 lines (37 loc) · 1.12 KB
/
TASK1.cpp
File metadata and controls
41 lines (37 loc) · 1.12 KB
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
#include<iostream>
#include<ctime>
using namespace std;
int main(){
cout << "Welcome to the Number Guessing Game!\n" ;
cout << "I have selected a number between 1 and 100. Can you guess it?\n" ;
int Num;
int att; //
int userNum=0;//user input number
// Generating different random numbers each time game will run
srand(time(0));
Num=rand()%100;
//Rang of the number between 1 t0 100;
for(int att=0;att<7;att++){
cout<<"enter the number :";
cin>>userNum;
if(Num==userNum){
cout<<"\nCongratulation you guess the correct number "<<userNum;
break;
}
else if(Num>userNum){
cout<<"\n your guessing number is too low ,attemp left "<<(7-(att+1));
if((7-(att+1))>0){
cout<<"\ntry again :";
}
}
else if(Num<userNum){
cout<<"\n your guessing number is too high ,attemp left "<<(7-(att+1));
if((7-(att+1))>0){
cout<<"\ntry again :";
}
}
}
if(att==0){
cout<<"\nyou failed to guess the number is "<<Num;
}
}