-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
executable file
·46 lines (38 loc) · 1.12 KB
/
test.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
#include <iostream> // std::cout, std::cin
#include <cstdlib> // random number
#include <stdio.h> //for printf
using namespace std;
//my program in C++
//to compile will be g++ numberguessinggame.cpp -o numberguessinggame.exe ; ./numberguessinggame.exe
int main()
{
int guess;
int minNumber = 1;
int maxNumber = 100;
srand (time(NULL)); /* random time generator */
int magicNumber = rand() % 100 + 1;
cout << "What is your favourite number!" << endl;;
cin >> guess;
cout << "The value you entered is " << guess << endl;;
/* initialize random seed: */
/* srand (time(NULL)); */
bool found = false;
while (!found) {
cout << "Guess the number between " << minNumber << " and " << maxNumber << ":" << endl;
int iguess;
cin >> iguess;
if (iguess == magicNumber){
found = true;
}
if (iguess < magicNumber){
cout << "Too Low" << endl;
}
if (iguess > magicNumber){
cout << "Too High" << endl;
}
}
printf("You got it!");
do {
cout << '\n' << "Press the Enter key to continue.";
} while (cin.get() != '\n');
}