Guess My Number

The times they are a-changin’.

This post seems to be older than 16 years—a long time on the internet. It might be outdated.

This weeks programming activity was actually pretty cool. We had to create a game that would generate a random integer between 1 and 10. The user then guesses a number and the computer tells you if you are high, low, or right on. Give it a whirl!

//Name: Andrew Ferguson
//Date: 2/6/2005
//Purpose: Make a program that makes you guess a number between 1 and 10


using namespace std;

int guessNum;
int userGuess;
char n;

int main(){
guessNum = 1+rand()%10;
cout << "Try to guess the number. It's between 1 and 10\n"; do{ cout << "What's your guess?\n"; cin >> userGuess;
if(userGuess < guessNum) cout << "You guessed too low.\n\n";& else if(userGuess > guessNum)
cout << "You guessed to high.\n\n"; } while(userGuess != guessNum); cout << "That's right! My number was " << guessNum << ".\n"; printf("Press any key to continue..."); n = getch(); return 0; } [/code]

Download guessGame