Thread: If Problem

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    114

    If Problem

    Code:
    if(input == "LOL")
        {
                 random = (rand() % ( 1 - 6 )) + 1;
                 
                 if( random == 1)
                 {
                 cout <<"You Stumble along the dirt road and find a penny\n";
                 money = money + 1;
                   if(counter >= 1)
                   {
                   counter = counter - 1;
                   }
                 }
                 if( random == 2)
                 {
                 cout <<"You reach into yer moms pocket and pull out a penny\n";
                 money = money + 1;
                   if(counter >= 1)
                   {
                   counter = counter - 1;
                   }
                 }
                 if(random == 3)
                 {
                 cout <<"As you search your couch you find a penny\n";
                 money = money + 1;
                   if(counter >= 1)
                   {
                   counter = counter - 1;
                   }
                 }
                 if(random == 4 && counter == 0)
                 {
                 cout <<"As you wander helplessly down the street you get knocked in the head.\n"
                      <<"You wake up later to find yourself in a alley and yer pockets empty\n";
                 money = 0;
                 counter = 5;
                 }
                 if(random == 5)
                 {
                 cout <<"You ask the mayor for bebe mooneys he gives u a penny\n";
                 money = money + 1;
                   if(counter >= 1)
                   {
                   counter = counter - 1;
                   }
                 }
                 if(random == 6)
                 {
                 cout <<"You Beg for mooneys and recieve a penny for a hard days work\n";
                 money = money + 1;
                   if(counter >= 1)
                   {
                   counter = counter - 1;
                   }
                 }
                 
                
        }
    For some strange reason when typing this it will some times not say any thing but it never says number 6 and im not sure why btw this is a snippet of the code not all

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The possible values of the % are 0, 1, 2, 3, and 4. Adding one gives 1, 2, 3, 4, and 5. So not getting 6 is exactly what you should expect.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    I figured it out :P
    Last edited by Nathan the noob; 01-26-2009 at 09:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

Tags for this Thread