Mr. Umar throws two dice multiple times. Every time he throws the first dice it shows the value 3 and the value of the second dice varies. He will get some coupons if the sum of the two dice value is even. Assuming the first dice value is 3, the result can be computed as sum=3+x, x varies from 1 to 6. The possible sum values would be 4, 5, 6, 7, 8, 9. If the sum is 4 then he will get movie tickets, if the sum is 6 then he will get a lunch coupon, if the sum is 8 he will get amazon prime coupon. Any other value he will not be eligible for any coupon.
Requirements
Depending on the result display the appropriate coupon Mr. Umar gets
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int sum;
int x;
srand(time(0));
//1. Capture the second dice value
x=(rand() % 6)+1;
//2. Compute the result using the expression res=3+x
sum=3+x;
//Depending on the result display the appropriate coupon Mr. Umar gets
//if the sum is 4 then he will get movie tickets,
if(sum==4){
printf("Mr. Umar gets movie tickets.\n");
}else
//if the sum is 6 then he will get a lunch coupon,
if(sum==6){
printf("Mr. Umar gets a lunch coupon.\n");
}else
//if the sum is 8 he will get amazon prime coupon.
if(sum==8){
printf("Mr. Umar gets amazon prime coupon.\n");
}
//Any other value he will not be eligible for any coupon.
else{
printf("Mr. Umar does not get any coupon.\n");
}
getchar();
getchar();
return 0;
}
Comments
Leave a comment