Guess My Number

07 Feb 2005 @22:31

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

#include <iostream.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>

using namespace std;

int guessNum;
int userGuess;
char n;

int main(){
    srand(time(0));
    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;
}

Download guessGame


Actions

Informations

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Code: To include code, bracket it with [code language="php"] and [/code].
Example: [code language="php"] echo "Hello, World!"; [/code]

Plugin Help: If your requesting help about a plugin, please provide as much information as possible. At the very least, include your WordPress Version and the Plugin Version!