First Exercise

This commit is contained in:
2025-02-20 23:51:20 +01:00
parent 2b700071aa
commit d580b385e5
27 changed files with 207 additions and 36 deletions

View File

@@ -0,0 +1,33 @@
#include <cstdlib>
#include <iostream>
#include <string>
#include "guess_a_number.h"
// NOTE: You cannot change this file, and you don't need to understand its
// content in order to solve your task. Feel free to look around, however,
// in case you're interested.
const std::string action = std::getenv("ACTION");
// This function returns a randomly chosen integer from the interval [1, max].
int randomly_choose_a_number(int max) {
return std::rand() % max + 1;
}
int choose_a_number(int max) {
if (action == "run") {
std::cout << "?\n";
// Just here to achieve the same output behaviour, in terms of newlines,
// when a user replaces
// std::cin >> number_to_guess;
// by
// number_to_guess = choose_a_number(MAX);
return randomly_choose_a_number(max);
} else {
int guess;
std::cin >> guess;
return guess;
}
}