Write a complete program in C for the following: Suppose you want to develop a p
ID: 3762443 • Letter: W
Question
Write a complete program in C for the following:
Suppose you want to develop a program to play the Lottery. The program randomly generates a Lottery of a two-digit number (any number from 10 to 99), prompts the user to enter a two-digit number, and determines whether the user wins according to the following rule:
If the user matches the lottery in exact order, the awards is $100,000.
If the user input matches the lottery digits, the awards is $50,000.
If one digit in the user input matches a digit in the lottery, the awards is $30,000.
The winning number is 65.
Input: 65
“Your ticket is 65. Congrats! You get 100000!”
Input: 56
“Your ticket is 56. All digits are a match but are not in the right order. You get 50000!”
Input: 50 (or 60)
“Your ticket is 50 (or 60). You matched one digit! You get 30000!”
“Sorry, you didn’t win.”
Explanation / Answer
int getLotterNumber(){
return rand()%100;
}
int prize1(int lotteryNo,int userNo){
return lotteryNo == userNo;
}
int prize2(int lotteryNo,int userNo){
int reverseUserNo = 0;
while( userNo > 0){
reverseUserNo = reverseUserNo*10 + userNo % 10;
userNo = userNo / 10;
}
return lotteryNo == reverseUserNo;
}
int prize3(int lotteryNo,int userNo){
int a[2],i,j;
a[0] = lotteryNo % 10;
lotteryNo = lotteryNo / 10;
a[1] = lotteryNo % 10;
int b[2];
b[0] = userNo % 10;
userNo = userNo / 10;
b[1] = userNo % 10;
for(i = 0; i < 2 ; i++)
for(j = 0; j < 2; j++)
if( a[i] == a[j])
return 1;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.