aboutsummaryrefslogtreecommitdiff
path: root/CST 126/Homework 1/GuessingHelper.hpp
blob: 15875ca61337debcea3ec1dc9046dc17fe86e4bc (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
#ifndef GUESSING_HELPER_HPP
#define GUESSING_HELPER_HPP
#include "CurrencyHelper.hpp"
#include <random>

int RandomNumberGenerator(const int& LowerBound, const int& UpperBound);
void GuessingGame();

int RandomNumberGenerator(const int& LowerBound, const int& UpperBound)
{
	std::random_device dev;
	std::mt19937 rng(dev());
	std::uniform_int_distribution<std::mt19937::result_type> dist(LowerBound, UpperBound);
	const int Random_Number = dist(rng);
	return Random_Number;
}

void GuessingGame()
{
	system("cls");
	int GoldenSnitch = 0;
	int UserGuess = 0;
	size_t NumberOfGuesses = 0;
	GoldenSnitch = RandomNumberGenerator(1, 10000);

	do
	{
		UserGuess = InputSelectionInt("Guess a number between 1 and 10,000 :");
		system("cls");
		if (UserGuess == GoldenSnitch)
		{
			std::cout << "\033[32mHooray! YOU WON!!!!$$$$\033[0m" << " It took you #" << NumberOfGuesses << " Tries!!!" << std::endl;
			return;
		}
		if (UserGuess < GoldenSnitch)
		{
			std::cout << "Your number is less than the winning value, try a number with a larger magnitude!" << std::endl;
		}
		if (UserGuess > GoldenSnitch)
		{
			std::cout << "Your number is greater than the winning value, try a number with a smaller magnitude!" << std::endl;
		}
		NumberOfGuesses++;
		if (NumberOfGuesses == 20)
		{
			std::cout << "I'm sorry to inform you of your loss, but there's always another day!" << std::endl;
		}
		std::cout << "Try #" << NumberOfGuesses << std::endl;
	} while (NumberOfGuesses != 20);
	
}

#endif