Question: Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an

Code in C# please.

Write a program that will use the greedy algorithm.

This program will ask a user to enter the cost of an item.

This program will ask the user to enter the amount the user is paying.

This program will return the change after subtracting the item cost by the amount paid.

Using the greedy algorithm, the code should check for the type of bill.

Example:

Cost of item is $15.50 User pays a $20 bill

$20 - $15.50 = $4.50

Greedy algorithm will then return the user change in bills by checking every bill starting from $20

$20 <= $4.50? no skip

$10 <= $4.50? no skip

$5 <= $4.50? no skip

$1 <= $4.50? yes store $1 and subtract from total

$1 <= $3.50? yes store $1 and subtract from total. Etc

Final output should be User will get 4 dollar bills and 2 quarters.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!