|
|
|
@ -2,25 +2,25 @@
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
int check_number(char* number, int* checked_number) {
|
|
|
|
|
int check_number(std::string number, int* checked_number) {
|
|
|
|
|
std::size_t pos;
|
|
|
|
|
*checked_number = std::stoi(number, &pos);
|
|
|
|
|
*checked_number = std::stoi(number, &pos); // how to properly type check? or is that not necessary?
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int guess(int to_guess) {
|
|
|
|
|
std::cout << "Take a guess!" << std::endl;
|
|
|
|
|
char* guess;
|
|
|
|
|
std::string guess;
|
|
|
|
|
std::cin >> guess;
|
|
|
|
|
int guess_number;
|
|
|
|
|
int check = check_number(guess, &guess_number);
|
|
|
|
|
if (check < 0)
|
|
|
|
|
return check;
|
|
|
|
|
if (!guess_number == to_guess) {
|
|
|
|
|
if (!(guess_number == to_guess)) {
|
|
|
|
|
if (guess_number < to_guess)
|
|
|
|
|
std::cout << "Your number is too small.";
|
|
|
|
|
std::cout << "Your number is too small." << std::endl;
|
|
|
|
|
else
|
|
|
|
|
std::cout << "Your number is too big.";
|
|
|
|
|
std::cout << "Your number is too big." << std::endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
@ -46,12 +46,13 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
int check = check_number(argv[1], &max);
|
|
|
|
|
if (check < 0)
|
|
|
|
|
return check;
|
|
|
|
|
} else
|
|
|
|
|
std::cout << "Using max of " << max << std::endl;
|
|
|
|
|
} else
|
|
|
|
|
std::cout << "Using default max of 10" << std::endl;
|
|
|
|
|
|
|
|
|
|
std::cout << "Do you want to play? (y/n)" << std::endl;
|
|
|
|
|
char* answer;
|
|
|
|
|
std::cin >> answer;
|
|
|
|
|
std::string answer;
|
|
|
|
|
std::cin >> answer;
|
|
|
|
|
if (answer[0] == 'y') {
|
|
|
|
|
int check = play(max);
|
|
|
|
|
if (check < 0) {
|
|
|
|
|