today was a little different

Published October 15, 2004
Advertisement
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#includeusing 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.
Previous Entry I hate the dentist
Next Entry back on track!
0 likes 3 comments

Comments

Gaiiden
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
October 16, 2004 02:50 AM
johnhattan
. . .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.
October 16, 2004 07:44 AM
hothead
thanks i didn't even notice that.
October 16, 2004 11:32 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

artwork..or is it?

1240 views

OpenGL!

1206 views

sprites!

1198 views

API madness!!

1025 views

got a new book

880 views

levesl gain gone!

950 views

what happened?

1000 views

text based madness

990 views
Advertisement