1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help with this C code.. please..

Discussion in 'C' started by Jcs, Oct 8, 2010.

  1. Jcs

    Jcs New Member

    Joined:
    Oct 8, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hey guys, im trying to make this lottery game work.. I know that the line that says 10+rand()%90 is incorrect. What can i do to make it better. You dont have to give me the answer if you dont want to. just point me in the right direction please. ive been working on it for a few hours and its frustrating me..

    am i even using the rand number correectly?

    please and thank you.


    please help.. thank you..
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    10+rand()%90
    int main()
    {
    input-input%10)/10
    
    if(input==random number)
    {
          printf("You have won $10000\n"); 
          break;
    }
    else
    {
         if (input%10==random number || ((input-input%10)/10)==random number)
    {
          printf("You have won $1000\n");
           break;
    }
         printf("You have won nothing\n");
    }
        return 0;
    }
     
    Last edited by a moderator: Oct 9, 2010
  2. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    see the code below

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main(){
        srand(time(NULL));
        int number=10+rand()%90;
        printf("\n hint=%d",number);
        int input=0;
        printf("\nguess a number:");
        scanf("%d",&input);getchar();
    
    if(input==number){
        printf("You have won $10000\n");
    }
    else if (input%10==number || ((input-input%10)/10)==number){
        printf("You have won $1000\n");
    }else
        printf("You have won nothing\n");
    getchar();
    return 0;
    } 
    
    
     

Share This Page