-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomnum.cpp
More file actions
35 lines (26 loc) · 810 Bytes
/
randomnum.cpp
File metadata and controls
35 lines (26 loc) · 810 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
#include <iostream>
#include <stdlib.h>
#include <time.h>
int main() {
int number, guess, null;
srand (time(NULL));
number = rand() % 1000 + 1;
std::cout << "Guess the number between 1-1000!";
Guess:
std::cin >> guess;
if (guess > number) {
std::cout << "The number is lower! \n\n";
goto Guess;
} else if (guess < number) {
std::cout << "The number is higher! \n\n";
goto Guess;
} else if (guess == number){
std::cout << "You got it right! The number was " << number << "!";
std::cout << "Press any key, and then Enter to exit";
std::cin >> null;
return 0;
} else {
std::cout << "That is not a number. Enter a number \n\n";
goto Guess;
}
}