-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathguessingGame.cpp
More file actions
executable file
·48 lines (46 loc) · 1.13 KB
/
guessingGame.cpp
File metadata and controls
executable file
·48 lines (46 loc) · 1.13 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
42
43
44
45
46
47
48
#include<iostream>
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
// This program creates a random number and compares it to your guess. It then evaluates how many guesses you had.
int main() {
bool redo = true;
// restart
while (redo == true) {
bool stillPlaying = true;
int counter = 0;
int randomNumber = 0;
int yourNumber = 0;
// below is the random number generator
srand (time(NULL));
randomNumber = rand() % 100;
srand(time(0));
while (stillPlaying == true) {
// win conditions
cout<<"Please enter your number: ";
cin>>yourNumber;
counter++;
if (yourNumber == randomNumber) {
cout<<"You won!" << endl;
cout<<"Guesses: " << counter;
stillPlaying = false;
} else if (yourNumber <= randomNumber) {
cout<<"Your guess is too low! ";
stillPlaying == true;
} else {
cout<<"Your guess is too high. ";
stillPlaying == true;
}
}
// restart conditions
cout<<"Play again? Y to play again or N to end game."<<endl;
string input;
cin>>input;
if (input == "Y") {
redo == true;
} else {
redo == false;
break;
}
}
}