//GuessMyNumber3
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//function prototypes
int getRandomNumber();
int getUserGuess();
void tooHigh();
void tooLow();
void congratulations(int);
int main()
{
int theNumber;
int guess;
int tries = 0;
srand(time(0));
theNumber = getRandomNumber();
do
{
guess = getUserGuess();
tries++;
if(guess > theNumber)
tooHigh();
if(guess < theNumber)
tooLow();
}while(guess != theNumber);
congratulations(tries);
system("Pause");
return 0;
}
int guess, tries = 0, theNumber;
int getRandomNumber()
{
srand(time(0));
int theNumber = rand() % 100 + 1;
}
int getUserGuess()
{
cout << "Enter a guess: ";
cin >> guess;
++tries;
}
void tooHigh()
{
if (guess > theNumber)
cout << "Too High!\n\n";
}
void tooLow()
{
if (guess < theNumber)
cout << "Too Low!\n\n";
}
void congratulations(int x)
{
cout << "\nThat's it! You got it in " << tries << "guesses!\n";
}
This post has been edited by rachelw1023: 25 April 2009 - 04:21 PM

New Topic/Question
Reply




MultiQuote






|