forked from R3DHULK/cpp-for-gamers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simon-says.cpp
72 lines (64 loc) · 1.23 KB
/
simon-says.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
#include <iostream>
#include <ctime>
using namespace std;
// Number of turns to complete the game
const int NUM_TURNS = 5;
// Game objects
int sequence[NUM_TURNS];
int input[NUM_TURNS];
// Generate a random sequence of numbers
void generate_sequence()
{
srand(time(NULL));
for (int i = 0; i < NUM_TURNS; i++)
{
sequence[i] = rand() % 4 + 1;
}
}
// Display a sequence of numbers
void display_sequence()
{
cout << "Simon says: ";
for (int i = 0; i < NUM_TURNS; i++)
{
cout << sequence[i] << " ";
}
cout << endl;
}
// Get user input for the sequence
void get_input()
{
cout << "Enter the sequence (separated by spaces): ";
for (int i = 0; i < NUM_TURNS; i++)
{
cin >> input[i];
}
}
// Compare the user input to the sequence
bool compare_sequence()
{
for (int i = 0; i < NUM_TURNS; i++)
{
if (input[i] != sequence[i])
{
return false;
}
}
return true;
}
int main()
{
cout << "*** Simon Says ***" << endl;
generate_sequence();
display_sequence();
get_input();
if (compare_sequence())
{
cout << "Correct!" << endl;
}
else
{
cout << "Incorrect!" << endl;
}
return 0;
}