-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHigh-LowGame.cpp
More file actions
54 lines (40 loc) · 934 Bytes
/
High-LowGame.cpp
File metadata and controls
54 lines (40 loc) · 934 Bytes
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
//Stephanie Lab Group #2
//High-Low Game
#include <iostream>
#include <ctime>
#include <time.h>
using namespace std;
int main()
{
int seed, systemNum, choice, guesses = 0;
char again;
do
{
cout << "A random number has been generated. Try and guess it!\n" << endl;
seed = (time(NULL));
srand(seed);
systemNum = (1 + rand() % 1000);
do
{
cout << "Your guess: ";
cin >> choice;
if (choice > systemNum)
{
cout << "Your guess is too high!\n\n";
}
else if (choice < systemNum)
{
cout << "Your guess is too low!\n\n";
}
guesses++;
} while (choice != systemNum);
cout << "\nCongratulations! Your guess is correct!" << endl;
cout << "The number was " << systemNum << endl;
cout << "It took you " << guesses << " try/tries!\n" << endl;
cout << "Play again? [y/n]: ";
cin >> again;
system("cls");
guesses = 0;
} while (again == 'Y' || again == 'y');
return 0;
}