blob: 3bd8a17de10511fe7f0ee630489f7d18ba7e3f8a (
plain) (
blame)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#ifndef GUESSINGGAME_H
#define GUESSINGGAME_H
#include <iostream>
#include "clear.hpp"
#include "getrandom.hpp"
using std::cout;
using std::cin;
using std::endl;
inline void Guess(int &input, const int count)
{
if (count != 20)
cout << "This is guess " << count << ".\nEnter your guess: ";
else
cout << "\nLast chance! Enter your best guess: ";
cin >> input;
}
inline void HighLow(const int random, const int input, const int count)
{
cout << "\n";
if (random < input)
cout << input << " is greater than the number.";
else if (random > input)
cout << input << " is less than the number.";
else
cout << input << " is correct!";
}
inline bool WinLoseAgain(const int random, const int input)
{
char again;
if (random == input)
{
cout << "\nCongrats, you win!";
}
else
{
cout << "\nOh no! You lost! The correct guess was: " << random;
}
cout << "\nWould you like to play again? (Y/N): ";
cin >> again;
if (again == 'Y')
return true;
else
return false;
}
inline void GuessingGame()
{
const int random = GetRandom(1000, 1);
int input = 0;
int count = 1;
ClearScreen();
cout << "*************************************************************\n";
cout << "Welcome to the guessing game!\nYou have 20 guesses to guess a number between 1-1000.\n";
while (input != random && count != 21)
{
Guess(input, count);
HighLow(random, input, count);
count++;
}
if (WinLoseAgain(random, input) == true)
GuessingGame();
}
#endif
|