-
Notifications
You must be signed in to change notification settings - Fork 1
/
Number_Guessing_Game---CodSoft_Task-1.cpp
87 lines (84 loc) · 2.8 KB
/
Number_Guessing_Game---CodSoft_Task-1.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <bits/stdc++.h>
#include <iostream>
#include<cstdlib>
using namespace std;
int main()
{
int sp, num_range, real_num, guess_num, guess_count = 0;
start:
cout<<"-------------------------------------------------------------------------"<<endl;
cout<<"-------------------- WELCOME TO NUMBER GUESSING GAME --------------------"<<endl;
cout<<"-------------------------------------------------------------------------"<<endl;
cout<<"Choose one option ---> "<<"\n"<<endl;
cout<<"1.>>> Play the Game >>>"<<endl;
cout<<"2.>>> See the last Game Score >>>"<<endl;
cout<<"3.>>> Exit from the Game >>>"<<endl;
cout<<"\n"<<"Enter Your Option : ";
cin>>sp;
switch(sp)
{
case 1:
cout<<"\n"<<"Let's Start the Game..."<<"\n"<<endl;
goto play;
break;
case 2:
if(guess_count == 0)
{
cout<<"\n"<<"You haven't played the game once yet..."<<"\n"<<endl;
}
else if(guess_count == 1)
{
cout<<"\n"<<"In the Last Game, you won the game in "<<guess_count<<"st Try...!"<<"\n"<<endl;
}
else
{
cout<<"\n"<<"In the Last Game, you won the game in "<<guess_count<<" Tries..."<<"\n"<<endl;
}
goto start;
break;
case 3:
cout<<"\n"<<"Thanks for Playing the Game...!"<<"\n"<<endl;
exit(0);
break;
default:
cout<<"\n"<<"Invalid Option Choice... Please Try Again..."<<"\n"<<endl;
goto start;
}
play:
guess_count = 1;
cout<<"-------------------------- NUMBER GUESSING GAME -------------------------"<<endl;
cout<<"\n"<<"Enter what would you like the range of the numbers to be? : ";
cin>>num_range;
srand(time(0));
real_num = rand() % (num_range+1);
do
{
cout<<"\n"<<"Enter your guess number : ";
cin>>guess_num;
if(guess_num > real_num)
{
guess_count += 1;
cout<<"The number is lower than you guess...";
}
else if(guess_num < real_num)
{
guess_count += 1;
cout<<"The number is higher than you guess...";
}
else
{
cout<<"\n"<<"Great.! You guessed the correct number...!!!";
if(guess_count == 1)
{
cout<<"\n"<<"You guessed the number in "<< guess_count <<"st Try.!!!"<<"\n"<<endl;
}
else
{
cout<<"\n"<<"You guessed the number in "<< guess_count <<" Tries...!"<<"\n"<<endl;
}
goto start;
}
}
while(guess_num != real_num);
return 0;
}