First Exercise
This commit is contained in:
33
Projekt_1/Task_1/guess_a_number.cpp
Normal file
33
Projekt_1/Task_1/guess_a_number.cpp
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user