Page 1 of 1

help with c++

PostPosted: Sat Mar 17, 2007 2:53 am
by tequila stu
Hey, I am just wondering if anyone on here knows c++.

I have got a piece of coursework to do for the 10th of April that requires a random number generator and the ability to save and re-call the numbers. now as I have never used a R.N.G before I am absolutely stumped. I can get it to generate the numbers but can't quite seem to figure out how to store them.

Any help is appreciated.

*edit*

almost forgot, this is the generator I am using.

Code: Select all
    {
    srand((unsigned)time(0));
    float lowest=-10, highest=10;
    float range=(highest-lowest)+1;
    for(float index=0; index<8; index++){
        rw1 = lowest+float(range*rand()/(RAND_MAX + 100));
        cout << setprecision(2) << setiosflags(ios::fixed);


        cout << endl;
        system ("pause");

        }

PostPosted: Sat Mar 17, 2007 5:54 am
by Predaprince
I wish I could help, but I don't know much of C++. I use Python for most of my programming.

Good luck with it, though.

PostPosted: Sat Mar 17, 2007 5:57 am
by Stormwolf
I haven't used C++ in over 4 years, I can't remember a thing about it, sorry :-(

Re: help with c++

PostPosted: Sat Mar 17, 2007 9:41 am
by The Happy Locust
funny, looks like that code isn't printing anything.

Okay, the easiest way to store the random numbers is either in an array or a linked list.

the current code:
Code: Select all
for(float index=0; index<8; index++){
        rw1 = lowest+float(range*rand()/(RAND_MAX + 100));


updated code
Code: Select all
for (float index=0; index<8; index++){
    randomArray[index] = lowest+float(range*rande()/RAND_MAX + 100);


just make an array of whatever number of objects you need and save the random number directly to it. Obviously, you need to create the array first. hope that helps.

PostPosted: Sat Mar 17, 2007 11:15 am
by Bed Bugs
Damn, I learned C++ and Java a year and a half ago and forgot most of it. Hence why I'm not a programmer anymore. :lol:

PostPosted: Sat Mar 17, 2007 11:56 am
by The Happy Locust
Fender Bender wrote:Damn, I learned C++ and Java a year and a half ago and forgot most of it. Hence why I'm not a programmer anymore. :lol:


Don't feel bad. I've got a degree and I still had to look up my old homework to remember that.

Re: help with c++

PostPosted: Sat Mar 17, 2007 6:34 pm
by tequila stu
The Happy Locust wrote:funny, looks like that code isn't printing anything.

Okay, the easiest way to store the random numbers is either in an array or a linked list.

the current code:
Code: Select all
for(float index=0; index<8; index++){
        rw1 = lowest+float(range*rand()/(RAND_MAX + 100));


updated code
Code: Select all
for (float index=0; index<8; index++){
    randomArray[index] = lowest+float(range*rande()/RAND_MAX + 100);


just make an array of whatever number of objects you need and save the random number directly to it. Obviously, you need to create the array first. hope that helps.


yeah...i just realised i forgot to paste in the part that shows the numbers..


thanks for the help man....much appreciated.