X
xeys_00
#include<iostream>
#include<cstdlib>
//This program will be a number guessing game
int main()
{
//variables for the game
int number_of_tries=0;//how many times did it take to get it right?
int current_guess=0;//the number being currently tried
int upper_limit=100;
int lower_limit=1;
int correct_number=rand()%100;//the correct number will be from no
higher than 100
while (correct_number != current_guess)
{
//user interaction
std::cout << "What is your guess? The correct number will be no higher
than 100, or lower than 1.\n";
std::cin >> current_guess;//user inputs his guess
if (current_guess > upper_limit || current_guess < lower_limit)
{
std::cout << "What, you can't read directions? The number has to be
no higher than 100, or lower than 1!!! You're Fired!!!!!\n";
std::abort();//kicks user out if input is bad
}
else if (current_guess < correct_number)
{
std::cout << "Your guess is too low. Try again\n";
number_of_tries++;
}
else if (current_guess > correct_number)
{
std::cout << "Your guess is too high. Try again\n";
number_of_tries++;
}
else if (current_guess == correct_number)
{
std::cout << "Good job! You guessed the right number!!!\n";
std::cout << "It only took you "<< number_of_tries << " tries!\n";
break;
}
}
return 0;
}
All is good for the first run. Then the wierdest thing happens... The
"random" number is always the same forever afterwards.
#include<cstdlib>
//This program will be a number guessing game
int main()
{
//variables for the game
int number_of_tries=0;//how many times did it take to get it right?
int current_guess=0;//the number being currently tried
int upper_limit=100;
int lower_limit=1;
int correct_number=rand()%100;//the correct number will be from no
higher than 100
while (correct_number != current_guess)
{
//user interaction
std::cout << "What is your guess? The correct number will be no higher
than 100, or lower than 1.\n";
std::cin >> current_guess;//user inputs his guess
if (current_guess > upper_limit || current_guess < lower_limit)
{
std::cout << "What, you can't read directions? The number has to be
no higher than 100, or lower than 1!!! You're Fired!!!!!\n";
std::abort();//kicks user out if input is bad
}
else if (current_guess < correct_number)
{
std::cout << "Your guess is too low. Try again\n";
number_of_tries++;
}
else if (current_guess > correct_number)
{
std::cout << "Your guess is too high. Try again\n";
number_of_tries++;
}
else if (current_guess == correct_number)
{
std::cout << "Good job! You guessed the right number!!!\n";
std::cout << "It only took you "<< number_of_tries << " tries!\n";
break;
}
}
return 0;
}
All is good for the first run. Then the wierdest thing happens... The
"random" number is always the same forever afterwards.