Updated to new Semester
This commit is contained in:
48
Vorkurs/Projekt_1/Task_2/main.cpp
Normal file
48
Vorkurs/Projekt_1/Task_2/main.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <iostream>
|
||||
#include "guess_a_number.h"
|
||||
|
||||
int main() {
|
||||
int number_to_guess; // The number to guess
|
||||
int max_attempts; // The guessed number
|
||||
|
||||
std::cout << "Number to guess: ";
|
||||
number_to_guess = choose_a_number(10); // Randomly choose a number from the interval [1, 10]
|
||||
|
||||
std::cout << "Number of attempts: ";
|
||||
std::cin >> max_attempts;
|
||||
|
||||
// Make sure that the player has at least one attempt
|
||||
if (max_attempts < 1) max_attempts = 1;
|
||||
|
||||
int attempts = 0; // Attempts made so far
|
||||
bool play = true; // false once the game is over
|
||||
|
||||
while (play) {
|
||||
print_attempts_left(max_attempts - attempts);
|
||||
|
||||
// *** Part 1: input the next guess ****************************************
|
||||
int guess; // The user's guess
|
||||
//PART1_read_next_guess(guess);
|
||||
std::cout << "Your guess: ";
|
||||
std::cin >> guess;
|
||||
|
||||
// *** Part 2: handle the guess the user made *****************************
|
||||
//PART2_handle_guess(guess, number_to_guess, play);
|
||||
if (guess == number_to_guess) {
|
||||
print_you_won(guess);
|
||||
play = false;
|
||||
} else {
|
||||
print_wrong_guess(guess);
|
||||
}
|
||||
|
||||
// *** Part 3: finish up the round ****************************************
|
||||
if (play) {
|
||||
//PART3_finish_round(number_to_guess, max_attempts, attempts, play);
|
||||
attempts += 1;
|
||||
if (attempts == max_attempts) {
|
||||
print_you_lost(number_to_guess, attempts);
|
||||
play = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user