Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Newbie question
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
AsianSensation




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
AsianSensation




PostPosted: Fri Jun 13, 2003 5:02 pm   Post subject: (No subject)

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




PostPosted: Fri Jun 13, 2003 5:04 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
AsianSensation




PostPosted: Fri Jun 13, 2003 5:11 pm   Post subject: (No 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
Catalyst




PostPosted: Fri Jun 13, 2003 8:59 pm   Post subject: (No subject)

asian is right is goes from 0 to RAND_MAX
Homer_simpson




PostPosted: Fri Jun 13, 2003 9:01 pm   Post subject: (No subject)

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




PostPosted: Sat Jun 14, 2003 1:10 pm   Post subject: (No subject)

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




PostPosted: Sat Jun 14, 2003 7:51 pm   Post subject: (No subject)

ezz up on him, he's just beginning
Sponsor
Sponsor
Sponsor
sponsor
SilverSprite




PostPosted: Sat Jun 14, 2003 10:08 pm   Post subject: (No 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.
AsianSensation




PostPosted: Sat Jun 14, 2003 10:24 pm   Post subject: (No subject)

yeah, i know, i should be ashamed of myself, after all the stuff SilverSprite taught me.....*sob sob Crying or Very sad
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: