-
Notifications
You must be signed in to change notification settings - Fork 1
/
GuessingGame_2.0.cpp
46 lines (35 loc) · 1.04 KB
/
GuessingGame_2.0.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
// 2019 C++ Learning Repo
//Guessing Game 2.0
//written by rwx-777
#include <iostream>
#include <random>
using namespace std;
int main() {
//use a random Number everytime programm is executed
random_device dev;
mt19937 rng(dev());
uniform_int_distribution<mt19937::result_type> dist6(1,6); //random number will be anywhere between 1 and 6
int secretNumber = dist6(rng);
//cout << secretNumber;
//int secretNumber = 7;
int guess;
int guessCount = 0;
int guessLimit = 5;
bool outOfGuesses = false;
while(secretNumber != guess && !outOfGuesses){ //As long as the Secretd Number is not the same as the guessed Number
//keep the guessing game going
if (guessCount < guessLimit) {
cout << "Enter a guess: ";
cin >> guess;
guessCount++; //Keeps track of how many times the User has guessed
}else{
outOfGuesses = true;
}
}
if(outOfGuesses) {
cout << "You loose!\n";
}else {
cout << "You Win!\n";
}
return 0;
}