We have to write a guess the numver game program in visual c++. This is what it reads your program chosesthe number to be guessed by selecting an integer at random in the range 1 to 1000. The Programthen displays the following
I have a number between 1 and 1000
can you guess my number?
Please type your first guess.
The player then typesa first guess. With one of the following.
excellent
too low try again
too high try again
It then wants you to modify the program to count the number of guesses the player makes. If the number is 10 or fewer print "either you know the secret or you got lucky. " If player guesss the number in ten tries then print " you should do better"
THis is what I have.
#pragma once
class GuessNumber
{
public:
GuessNumber(void);
~GuessNumber(void);
};
#include %26lt;iostream%26gt;
#include %26lt;cstdlib%26gt;
#include %26lt;ctime%26gt;
#include "GuessNumber.h"
using namespace std;
int main()
{
srand(time(0)); // seed random number generator
int theNumber = rand() % 100 + 1; //random number between 1 and 100
int tries = 0, guess;
cout %26lt;%26lt; "\tWelcome to Guess My Number\n\n";
//Guessing Loop
do
{
cout %26lt;%26lt; "Enter a guess:";
cin %26gt;%26gt; guess;
++tries;
if (guess %26gt; theNumber)
cout %26lt;%26lt; "Too high!\n\n";
if (guess %26lt; theNumber)
cout %26lt;%26lt; "Too low!\n\n";
} while (guess != theNumber);
cout %26lt;%26lt; "\nThat's it! You got it in" %26lt;%26lt; tries %26lt;%26lt; "guesses!\n";
return 0;
}
C++ Computer Guess the number game programming help Visual C++?
Your code looks good so far....i guess there is no reason to add the final details since you clearly have a grasp of what is left. Good job
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment