By using this site, you agree to our Privacy Policy and our Terms of Use. Close

Forums - General Discussion - Huh, 6, why 6???

also, are you sure you remembered to add in the <ctime> library that you need to get the system time to work properly?



Seppukuties is like LBP Lite, on crack. Play it already!

Currently wrapped up in: Half Life, Portal, and User Created Source Mods
Games I want: (Wii)Mario Kart, Okami, Bully, Conduit,  No More Heroes 2 (GC) Eternal Darkness, Killer7, (PS2) Ico, God of War1&2, Legacy of Kain: SR2&Defiance


My Prediction: Wii will be achieve 48% market share by the end of 2008, and will achieve 50% by the end of june of 09. Prediction Failed.

<- Click to see more of her

 

Around the Network
Grey Acumen said:
I THINK C++ has a separate thing that you need to do to randomize the random number.

Basically, if you run the program and ask for a random number, it'll keep on giving you random numbers BUT with each time you run the program you will get the same set of random numbers because it's working with the same seed that it pulls it's random numbers from. In order to make it truly random, you need to randomize the seed as well.

I could be misunderstanding your problem, or remembered a different programming language, but I'll check it out. I do know C++, so just give me a second to read through your program

Yeah, that's the problem.

I just can't remember what the line code he needs is.  It's been two years since I'v eworked with C++.  



Yeah I did, here's my new code:

#include<cstdlib>
#include<ctime>
#include<iostream>
using namespace std;
int main()

{
    system("TITLE COOKIE JAR GUESSING GAME");
    system("COLOR 2");
    int icookies;
    int ijar;
    int iguess;
   
   
   
   
    srand((unsigned int)icookies);
    icookies = rand()%10+1;
    cout<<"guess how many cookies are in the jar"<<endl;
    cin>>iguess;
    if (iguess< icookies) {
              cout<<"too low"<<endl;
              }
           if (iguess == icookies){
                      cout<<"you win!"<<endl;
                      }
                      if (iguess > icookies) {
                                
                                 cout<<"too high" << endl;
                                 }
                                
                                      cin>>iguess;
                                      if (iguess< icookies) {
              cout<<"too low"<<endl;
              }
           if (iguess == icookies){
                      cout<<"you win!"<<endl;
                      }
                      if (iguess > icookies) {
                                
                                 cout<<"too high" << endl;
                                 }
                                      cin>>iguess;
                                      if (iguess< icookies) {
              cout<<"too low"<<endl;
              }
           if (iguess == icookies){
                      cout<<"you win!"<<endl;
                      }
                      if (iguess > icookies) {
                                
                                 cout<<"too high" << endl;
                                 }
                                    
                                      system("PAUSE");
                                      return(0);
                                      }



 

LOL!

Dude, you never changed the srand part in order to give it a different seed:

[srand((unsigned int)icookies);] needs to become [srand((unsigned)time(0));]



Seppukuties is like LBP Lite, on crack. Play it already!

Currently wrapped up in: Half Life, Portal, and User Created Source Mods
Games I want: (Wii)Mario Kart, Okami, Bully, Conduit,  No More Heroes 2 (GC) Eternal Darkness, Killer7, (PS2) Ico, God of War1&2, Legacy of Kain: SR2&Defiance


My Prediction: Wii will be achieve 48% market share by the end of 2008, and will achieve 50% by the end of june of 09. Prediction Failed.

<- Click to see more of her

 

^YYYYYYYYYYYYYYYYEAAAAAAAAAAAAAAAAAAHHHHHHHHHHHH!!!!!!!!! Thanks a lot!!!!



 

Around the Network

No prob. Just remember to go through it line by line when something isn't working. It's very easy to skip over something or to have a slight typo that can mess teh whole thing up.



Seppukuties is like LBP Lite, on crack. Play it already!

Currently wrapped up in: Half Life, Portal, and User Created Source Mods
Games I want: (Wii)Mario Kart, Okami, Bully, Conduit,  No More Heroes 2 (GC) Eternal Darkness, Killer7, (PS2) Ico, God of War1&2, Legacy of Kain: SR2&Defiance


My Prediction: Wii will be achieve 48% market share by the end of 2008, and will achieve 50% by the end of june of 09. Prediction Failed.

<- Click to see more of her

 

^ Yeah, thanks....I'll be sure to keep that in mind..