As per a report published by nerdwallet, the millennials have checked out on carrying cash. One of the reasons they prefer credit/debit card is that they want to minimize the cost of printing notes.

As an attempt to reduce the quantity of notes in hand of general public, a system has been proposed where you the given amount using least number of notes. You’re supposed to code that system as per the Indian currency system, following the instructions given below:

Part 1:
User will enter a starting amount n (0 < n <= 10,00,000). You have to find minimum number of notes/coins required to form that amount.
Available currency: Notes: ₹2000, ₹500, ₹200, ₹100, ₹50, ₹20, ₹10 Coins: ₹5, ₹2, ₹1

Part 2:
After this, you have to make the purchase using available notes/coins (that you have calculated in part 1).
For this: User will enter bill amount m (0 < m <= n, where m is cost and n is amount you have); you will pay it using available notes/coins. If it is not possible to form exact amount from available notes/coins than pay extra and get the change from shopkeeper (see examples given at the end for more clarity). Change given by shopkeeper should also be in minimum possible number of notes/coins.

Part 3:
Ask user whether he/she wants to pay another bill or exit.

Constraints:
1) You have to pay from available notes/coins.
2) Your available notes/coins will decrease when you pay and may increase when you get change.

Assumption:
1) Assume that the shopkeeper has every denomination available with him.

EXAMPLE:
Enter starting amount: 15550
Available Currency:
Rs. 2000 note X 7 => 14000
Rs. 500 note X 3 => 1500
Rs. 50 note X 1 => 50
Enter cost of item 1 : 50
PAID USING:
Rs. 50 note X 1 => 50

GOT CHANGE OF Rs. 0

Available amount after purchase of item 1 is 15500 as:
Rs. 2000 note X 7 => 14000
Rs. 500 note X 3 => 1500

Want to purchase more items (0 => NO | 1 => YES): 1
Enter cost of item 2 : 1400
PAID USING:
Rs. 500 note X 3 => 1500
GOT CHANGE OF Rs. 100 AS:Rs. 100 note X 1 => 100

Available amount after purchase of item 2 is 14100 as:
Rs. 2000 note X 7 => 14000
Rs. 100 note X 1 => 100

Want to purchase more items (0 => NO | 1 => YES): 1
Enter cost of item 4 : 14100
PAID USING:
Rs. 2000 note X 7 => 14000
Rs. 100 note X 1 => 100

GOT CHANGE OF Rs. 0

Available amount after purchase of item 4 is 0

Cannot continue as amount left is 0.
Press any key to exit.

You can email your solutions at training@core-solutions.in or join our WhatsApp community group to participate in discussion. We share monthly coding tasks and information that is valuable for both students and teachers. Our Community is a knowledge-sharing arena for students, teachers and professionals; an attempt to bridge the skill-gap between the academic institutions and the companies. JOIN NOW

For further queries, contact +91 7888671751.

Check out task for the month of April.