Answer to Question #217767 in C for dheeraj

Question #217767

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

  1. Capture the second dice value
  2. Compute the result using the expression res=3+x

Depending on the result display the appropriate coupon Mr. Umar gets


1
Expert's answer
2021-07-16T01:05:35-0400
#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;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS