• Advertisement
Sign in to follow this  
  • entries
    31
  • comments
    97
  • views
    13405

today was a little different

Sign in to follow this  

282 views

I got up at f**king 3:58 p.m this afternoon and im still tired [smile] i went over to my friends house and he wasn't there:( im almost halfway through my book im waiting on my dinner so i made this program
#include
#include
#include

using namespace std;

int main()
{
int num = ((rand() % 100) + 1); //make a random number between 1 and 100
int tries = 0;
int guess;
do
{
cout<<"enter a number between 1 and 100";
cin>> guess;
tries++;

if(guess > num)
cout<<"thats too high\n\n";
if(guess < num)
cout<<"thats too low\n\n";
}while(guess != num);
cout<<"you got it in"<}

and i hope my show comes on tonight.
Sign in to follow this  


3 Comments


Recommended Comments

you forgot to seed the random number generator

srand(time(0));

in case you've noticed that you're guessing the same number every time, this is why

Share this comment


Link to comment
. . .and put an "else" before that second if() statement. Since the second if() is irrelevent if the first succeeds, it should rightly be ignored if that's the case. Hence adding an "else" before the second if() will increase the speed of your program greatly.

Oh, and it should never take you more than seven guesses to get the right number.

Share this comment


Link to comment

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

  • Advertisement