Currency Exchange, II Solution

$30.00

Description

The Currency Exchange Counter at the airport is specialized in selling and buying US dollars. The US dollar bills in the market are 1, 2, 5, 10, 20, 50, 100, and 1000 dollars. The Counter have all these bills available. When a customer is buying a specific amount of US dollars, the counter agent is requested to give out the least number of dollar bills. Please help out the counter agent to write a C program that given the USD amount it would output the least number of US dollar bills.

Example program inputs and outputs are shown below.

  • ./a.out

Enter USD amount: 999

To pay:

9

$100 bills

1

$50

bill

2

$20

bills

1

$5

bill

2

$2

bills

  • ./a.out

Enter USD amount: 5555

To pay:

5 $1000 bills

5 $100 bills

1 $50 bill

1 $5 bill

If a particular type of dollar bill is not required, it will not be printed out. And, the USD amount is assumed to be an integer for this lab.

Notes.

  1. Create a directory lab02 and use it as the working directory.

  1. Name your program source file as lab02.c.

  1. The first few lines of your program should be comments as the following.

/* EE231002 Lab02 Currency Exchange, II ID, Name

Date:

*/

1

  1. After finishing editing your source file, you can execute the following command to compile it,

$ gcc lab02.c

If no compilation errors, the executable file, a.out, should be generated, and you can execute it by typing

$ ./a.out

  1. Typical inputs and outputs of the program execution have been shown above. But you should try a few more test cases to make sure your program functions correctly.

  1. After you finish verifying your program, you can submit your source code by

$ ee231002/bin/submit lab02 lab02.c

If you see a ”submitted successfully” message, then you are done. In case you want to check which file and at what time you submitted your labs, you can type in the following command:

$ ee231002/bin/subrec lab02

It will show the submission records for lab02.

  1. The objectives of this lab are:

7.1. Practice more linux commands,

7.2. Practice vim editor,

7.3. Practice conditional expressions.

  1. (Challenge) The USD coins in the market are 1 cent (penny), 5 cents (nickle), 10 cents (dime), and 25 cents (quarter). Modify the program such that it can handle fractional USD as well.

  1. The challenge is for your own practice, no need to turn them in.

2