Programming update
|
So here is the finished guessing game. I should have posted it way earlier because it already feels like I could do it better with the knowledge from the first lectures of this week. But I figure this is too basic a game to put any more time into, because regardless how perfect, it will always be a boring game to play.
#include
#include
#include
int random(int min, int max)
{
return min + (rand() % (max - min + 1));
}
int main(int argc, char* argv[])
{
int tries = 0;
srand((unsigned int)time(0));
int randomnumber = random(1, 100);
bool victory = false;
std::cout << "Guess the number between 1 and 100." << std::endl << std::endl;
//std::cout << "random(): " << randomnumber <> guess;
if (guess >= 1 && guess <= 100)
{
if (guess == randomnumber)
{
std::cout << "Correct! You win! ";
tries++;
break;
}
else if (guess < randomnumber)
{
std::cout << "Too low. Try again.n" < randomnumber)
{
std::cout << "Too high. Try again.n" << std::endl;
tries++;
}
}
else
{
std::cout << guess << " is not between 1 and 100, stupid! Counts as a guess anyway.n" << std::endl;
tries++;
}
}
if (tries == 1)
{
std::cout << "And on the first guess, too! You're a natural!nPress Enter to exit.n";
}
else
{
std::cout << "You needed " << tries << " guesses. Press Enter to exit.n" << std::endl;
}
std::cin.ignore(1024, 'n');
std::cin.get();
return 0;
}
|
