Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Need help with this C code.. please.. (http://www.go4expert.com/forums/help-c-code-t23525/)

Jcs 8Oct2010 23:02

Need help with this C code.. please..
 
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;
}


virxen 9Oct2010 04:06

Re: Need help with this C code.. please..
 
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;
}



All times are GMT +5.5. The time now is 04:07.