Commit fd102ffc authored by Martin Klimeš's avatar Martin Klimeš ❄️
Browse files

feat(game): added guess a number game

parent f9ad8563
Loading
Loading
Loading
Loading

main.cc

0 → 100644
+25 −0
Original line number Diff line number Diff line
#include <cstdlib>
#include <iostream>
#include <random>

const int high_bound = 100;

int main(int argc, char *argv[]) {

	int guess;
	int number = std::rand() % high_bound;
	std::cout << "I am thinking of number between 0 and " << high_bound << "\n";

	do {
		std::cout << "Guess a number: ";
		std::cin >> guess;
		if (number == guess) {
			std::cout << "Yes! I was thinking " << guess << '\n';
		} else {
			std::cout << "No, that's not quite it, my number was " << (number > guess ? "higher" : "lower") << '\n';
		}

	} while (guess != number);

	return 0;
}