This is for anyone that would like a piece of the code or would just like to see it finished (at least how I did it) in general. I hope this helps anyone who needs or would like to know how to do it and again, thank you so much Flying Dutchman and Nullw0rm :)
Here's the code. On my compiler I have 0 errors and it runs great but please let me know if you get errors or have problems running it:
//This is a very simple text based number guessing game in which the player gets 5 tries to guess the randomly
//generated number that is between 1 and 10.
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
srand( (unsigned)time( NULL ) );
int theNumber = (rand() % 10 + 1);
int playersGuess;
int tries = 0;
cout << "Hello and welcome! \n";
Sleep(3000);
cout << "Lets play guess my number! \n";
Sleep(3000);
for(int tries=0;tries<5||theNumber==playersGuess;tries++)
{
cout << "Please enter a number between 1 and 10: ";
cin >> playersGuess;
if (playersGuess == theNumber)
{
cout << "You won! \n";
Sleep(3000);
cout << "Thank you for playing! \n";
Sleep(3000);
}
else if (playersGuess > theNumber)
{
tries++;
cout << "Lower! \n";
}
else if (playersGuess < theNumber)
{
tries++;
cout << "Higher! \n";
}
if (tries == 4)
break;
}
{
cout << "I'm sorry, you lose! \n";
cout << "The answer is: " << theNumber;
cout << " \n";
}
cin.get ();
return 0;
}
Feel free to further simplify or enhance it in any way of course :)
Edited by RuneNova91, 30 July 2010 - 10:40 PM.
Code Update


Sign In
Create Account


Back to top









