Sign in to follow this  

help with a program

This topic is 4074 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok im using Dev-C++ and ive just created a guess the number game,i now need to find a way to allow the player to pick a number and the computer to guess it, if someone could post the code w/o telling me why it works that would be more helpfull because working it out will be more educational for me,thanks for your time.

Share this post


Link to post
Share on other sites
Hi there!

A solution to your problem would be to inverse it. You already know how to generate random numbers, and therefore you can use it to make the computer generate a random number and then check to see if the generated number is equal to the number the user has set. Try it.

Hope this helps!

Share this post


Link to post
Share on other sites
Yes, but remember that the computer already "knows" the answer(the user input the number to the computer), your job as a programmer is to hide that. So if the user inputs 78. Then make the computer generate numbers between 1-100. If the user inputs 999, make the computer generate numbers between 900-1000 etc.

Good luck!

Share this post


Link to post
Share on other sites
well so far i have the computer guessing my number and and me being able to tell it if its right or not,all i need to do is track its guesses and also tell it whether to be higher or lower,the tracking should not be a problem,but how do i go about telling it higher or lower?

Share this post


Link to post
Share on other sites
ok i need help working out how to tell the computer its too high or too low,

thanks in advance

#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
int number;
int tries = 0, guess;

cout << "\tWelcom to Guess My Number VS the computer!\n\n";
cout << "Please select a number ";
cin >> number;

char again = 'n';
while (again == 'n')
{
srand(time(0));
int guess = rand() % 100 + 1;

cout << guess;
cout << "\nIs this your number? (y/n)";
cin >> again;
++tries;
}

cout << "\nYes i won!" << tries << " guesses!\n";
system("PAUSE");
return 0;
}

Share this post


Link to post
Share on other sites

This topic is 4074 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this