Top Posters
Since Sunday
g
3
3
2
J
2
p
2
m
2
h
2
s
2
r
2
d
2
l
2
a
2
New Topic  
saiiranazashraf saiiranazashraf
wrote...
Posts: 3
Rep: 0 0
8 years ago
HEYY EVERYONE I HAVE AN ASSIGNMENT TO SUBMIT RELATED TO LOOPS AND I HAVE NO CLUE HOW TO SOLVE IT
IF SOME ONE CAN HELP THAT WILL BE REALLY GREAT

Suppose we can buy a juice can from the vending machine for 3 dirhams each. On every purchase of a can of
juice, there is a free coupon. We can redeem 4 coupons for one juice can from the machine. We would like
to know how many juice cans can be consumed, including those redeemed via coupons, if we have n
dirhams.
For example, if we have 20 dirhams then we can initially buy 6 cans of juice. This gives us 6 coupons. We can
redeem 4 coupons for 1 additional can of juice. This one additional can of juice adds one more coupon, so we
now have a total of 3 coupons when added to the 2 leftover from the original purchase. As a result we now
have 7 cans of juice and 3 leftover coupons.
Write a program that inputs the purchase amount of dirhams and outputs how many juice cans you can
collect after spending all your money and redeeming as many coupons as possible. Also output the number
of leftover coupons.
Hint: Use a while loop that redeems coupons for juice and calculates the new number of coupons. Continue
the loop as long as you have enough coupons to redeem for juice.
Read 389 times
1 Reply
Replies
Answer accepted by topic starter
bio_manbio_man
wrote...
Educator
Top Poster
Posts: 33233
8 years ago
Sign in or Sign up in seconds to unlock everything for free
1

Related Topics

New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  829 People Browsing
 191 Signed Up Today
Related Images
  
 222
  
 164
  
 4423
Your Opinion
Which 'study break' activity do you find most distracting?
Votes: 741