-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode for the game
44 lines (34 loc) · 940 Bytes
/
Code for the game
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
//
// main.cpp
// Guess the number
//
// Created by Martin Kalliola on 6.12.2020.
//
#include <iostream>
using namespace std;
int main(){
int numberToGuess = 0;
int numberGuessed = 0;
bool flag = false;
cout << "Please input a number: ";
cin >> numberToGuess;
if (!cin.fail()) {
while (flag == false) {
cout << "Try to guess the number: ";
cin >> numberGuessed;
if (!cin.fail()) {
if (numberGuessed > numberToGuess){
cout << "Number too big... TRY AGAIN!" << endl;
}
else if (numberGuessed < numberToGuess) {
cout << "Number too small.. TRY AGAIN!" << endl;
}
else {
cout << "YOU GUESSED RIGHT!!" << endl;
flag = true;
}
}
}
}
return 0;
}