Suppose you can buy a bag of mixed fruits from the store for $1. Inside every ba
ID: 3543039 • Letter: S
Question
Suppose you can buy a bag of mixed fruits from the store for $1. Inside every bag of
fruits is a coupon. You can redeem seven coupons for 1 bag of fruits. Write a program
that reads a number of dollars from the user and prints the total number of bags of fruits
you can get for that amount of money and the number of leftover coupons.
For example, say the user inputs 20 for the amount of dollars. Then, you can buy 20
bags of fruits with the $20 and then redeem 14 coupons for two more bags of fruits, the
two additional bags give you two more coupons so you now have a total of eight
coupons which gives you one more bag of fruits. As a result you now have 23 bags of
fruits and two leftover coupons.
Please make sure the code WORKS!
Explanation / Answer
#include <stdio.h>
int main(void) {
// your code goes here
int d,c,bag,redeem,leftover;
printf("Enter dollars:");
scanf("%d",&d);//enter dollars
bag=d/1;//calculate no. of bags intially based on dollar
c=bag*1;//as in each bag there is one coupon
while(c>=7)//till the no. of coupons is greater than 7 we can buy bags
{
redeem=c/7;//the no. of bags we can redeem
bag=bag+redeem;//te total bags
c=c-(redeem*7)+redeem;//total no. of coupon together with the coupons of redeemed bags
}
leftover=c;//the final coupon represents no. of leftover
printf("%d %d",bag,leftover);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.