Thread: Need help with my lottery game

  1. #1
    Registered User
    Join Date
    Nov 2014
    Location
    Estonia
    Posts
    5

    Need help with my lottery game

    Hi guys!
    Can anyone tell what's wrong with that?

    Need help with my lottery game-screenshot-2014-11-26-18-55-16-png

  2. #2
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Else statements do not need the conditional section

    on line 27 you have else (condition), you need to either change it to else if, or get rid of the (condition) portion.
    Code:
    int get_random_number(void)
    {
       return 4; //chosen by fair dice roll.
                 //guaranteed to be random
    }

  3. #3
    Registered User
    Join Date
    Nov 2014
    Location
    Estonia
    Posts
    5
    And now i find another issue Everything will work except prinf phrases. When i insert one number it woun't tell me if i win or not.
    Need help with my lottery game-screenshot-2014-11-26-19-34-22-png

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Why are you posting a C question in the C++ forum?

    Post code inside of code tags rather than a screen shot of your editor. Then we can compile and run your program, which would help diagnose the problem.

  5. #5
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Ask yourself this question

    How can a single number be both larger than a number AND smaller than the same number?
    Code:
    int get_random_number(void)
    {
       return 4; //chosen by fair dice roll.
                 //guaranteed to be random
    }

  6. #6
    Registered User
    Join Date
    Nov 2014
    Location
    Estonia
    Posts
    5
    So I made changes
    Is this right or should i use || ?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main (void)
    {
    int number, jackpot;
    srand (time(NULL));
    printf ("Insert one number between 1-100: ");
    scanf ("%d", &number);
    
    if (number > jackpot +10 && number < jackpot -20)
        {
            printf("Win is close!");
        }
        else if (number > number +5 && number < jackpot -10)
            {
                printf("Congratulations, You have won small price!");
            }
            else if (number > jackpot +11 && number < jackpot -22)
                {
                    printf("You haven't won anything!");
                }
                else if (number==jackpot)
                    {
                        printf("JACKPOT!");
                    }
        return 0;
    }

  7. #7
    Registered User
    Join Date
    Nov 2014
    Location
    Estonia
    Posts
    5

    Need help with my lottery game

    Hi guys!
    Can someone tell me how or what i must fix if...else statement that printf will work??


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
     
    int main (void)
    {
    int number, jackpot;
    srand (time(NULL));
    printf ("Insert one number between 1-100: ");
    scanf ("%d", &number);
     
    if (number > jackpot +10 && number < jackpot -20)
        {
            printf("Win is close!");
        }
        else if (number > number +5 && number < jackpot -10)
            {
                printf("Congratulations, You have won small price!");
            }
            else if (number > jackpot +11 && number < jackpot -22)
    
                {
                    printf("You haven't won anything!");
                }
                else if (number==jackpot)
                    {
                        printf("JACKPOT!");
                    }
        return 0;
    }

  8. #8
    Registered User
    Join Date
    Nov 2011
    Posts
    161
    What are you initializing jackpot to begin with?

  9. #9
    Registered User
    Join Date
    Nov 2014
    Location
    Estonia
    Posts
    5
    When i start that game, program must generate one number.(Jackpot number)

    Then comes the question and i must insert one number between 1 and 100.

    If..else block:
    #1 If my picked number different is +-10 from jackpot number, then program must print that "win is close!".
    #2 If my picked number different is +-5 from jackpot number, then program must print that "Congratulations, You have won small price!".
    #3 if my picked number is not #1 and #2 then program must print "You haven't won anything!"
    #4 If my picked number is jackpot number then program must print "JACKPOT!"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lottery - C Programm
    By Gooody in forum C Programming
    Replies: 6
    Last Post: 12-11-2014, 09:40 AM
  2. Lottery game Issue in Code...whats wrong?
    By thebridge in forum C Programming
    Replies: 6
    Last Post: 10-07-2010, 08:16 PM
  3. Lottery game
    By got1sleeve in forum C++ Programming
    Replies: 3
    Last Post: 02-16-2008, 01:55 PM
  4. Lottery game
    By geetard in forum C++ Programming
    Replies: 2
    Last Post: 12-20-2005, 12:50 AM
  5. Yet another lottery program
    By BungleSpice in forum C Programming
    Replies: 10
    Last Post: 04-01-2004, 02:08 PM