Computer Science Canada

Newbie question

Author:  AsianSensation [ Fri Jun 13, 2003 3:56 pm ]
Post subject:  Newbie question

I am just startin to learn C++, and I am using visual studio 6.0. I've been reading some tutorial off the net, and I tried to make a number guesser thingie, except it's not working, and I don't know whats wrong with it.
code:
#include <stdlib.h>
#include <iostream.h>

int main ()
{
        int num, guess;
       
        num=rand() % 100;

        int i=0;
        while (i<10);
        {
        cin >> guess;
       
        if (guess>num)
        {
                cout<< "High";
                i++;
        }
        else if (guess<num)
        {
                cout<< "Low";
                i++;
        }
        else
        {
                        cout<< "Yay!, You got it!";
        return 0;
        }
        }
        return 0;
}


so could someone help me?

Author:  AsianSensation [ Fri Jun 13, 2003 5:02 pm ]
Post subject: 

nvm, I fixed it, but I still don't know what was wrong with the other one.

Author:  Tony [ Fri Jun 13, 2003 5:04 pm ]
Post subject: 

i think rand() generates a random number between 0 and 1 Confused You gotta multiply by a 100 then convert it to integer.

code:

num = (int)(rand()*100)


or something like that

Author:  AsianSensation [ Fri Jun 13, 2003 5:11 pm ]
Post subject: 

I thought rand() gave u a number between 0 and Rand_Max, but that wasn't the problem, the problem is when I run it, I cannot even input. and I don't know y Confused

Author:  Catalyst [ Fri Jun 13, 2003 8:59 pm ]
Post subject: 

asian is right is goes from 0 to RAND_MAX

Author:  Homer_simpson [ Fri Jun 13, 2003 9:01 pm ]
Post subject: 

when i tried the program... i couldn't even input anything for some reason =/

Author:  SilverSprite [ Sat Jun 14, 2003 1:10 pm ]
Post subject: 

Wow no offense to you Asian, but that program is real sloppy! Soo many things wrong with it!!

Author:  krishon [ Sat Jun 14, 2003 7:51 pm ]
Post subject: 

ezz up on him, he's just beginning

Author:  SilverSprite [ Sat Jun 14, 2003 10:08 pm ]
Post subject: 

Lol you don't understand... I've showed him a few things, and he's had experience with turing.. tut tut tut asian i'm disappointed.

Author:  AsianSensation [ Sat Jun 14, 2003 10:24 pm ]
Post subject: 

yeah, i know, i should be ashamed of myself, after all the stuff SilverSprite taught me.....*sob sob Crying or Very sad


: