Suppose you want to develop a program to play lottery. The program randomly gene
ID: 3530831 • Letter: S
Question
Suppose you want to develop a program to play lottery. The program randomly generates a Lottery of a two-digit number, prompts the user to enter a two-digit number, and determines whether the user wins according to the following rule: 1. If the user matches the lottery in exact order , the awards is $10,000. 2. If the user input matches the lottery, the awards is $3,000. 3. If one digit in the user input matches a digit in the lottery, the awards is $1,000.I know that both my last two if condition are wrong and don't respect my constraint, can somebody give me the condition that will make the program work under the instruction Thanks #include#include#include int main(){ int num; printf("Enter a two digit number : "); scanf("%d",&num); srand( (unsigned)time( NULL ) ); int rand_num = (rand() % 99) + 1; printf("Random number :%d ",rand_num); if(rand_num == num){ printf("the award is $10,000"); return 0; } if(rand_num == (num/10) && (rand_num/10) == num ){ printf("the award is $3,000"); return 0; } if(rand_num == (num/10) || (rand_num/10) == num || rand_num == num || (rand_num/10) == (num/10) ){ printf("the award is $1,000"); return 0; } printf("Nothing matches"); return 0; } I know that both my last two if condition are wrong and don't respect my constraint, can somebody give me the condition that will make the program work under the instruction ThanksExplanation / Answer
Here's the problem, you are not comparing every number. Rather than give you the code I'll list the comparisons.
1. num == rand_num.
2. rand_num is 2 digits and num is 2 digits. We'll use an example to explain this one.
Let rand_num = 12. and num = 21.
First check: Is rand_num's first digit the same as num's second digit
To get first digit we divide by 10.
To get second digit we use mod 10 to get the remainder.
(rand_num/10) == (num)
If they are the same switch to check rand_num's second digit and num's first.
(rand_num) == (num/10)
If they both the same award the 3,000
3. Same concept with but have to check every spot.
rand First to num First
rand First to num Second
rand Second to num First
rand Second to num Second
GL on finishing your project. If you're still confused feel free to ask.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.