Currency Exchange Solution



A Currency Exchange Counter at the airport is specialized in selling and buying US dollars. The US Dollar (USD) vs. New Taiwan Dollar (NTD) exchange rate is

Buy: 32.47

Sell: 32.57

That is, the counter pays 32.47 NTD for 1 USD, and sells 1 USD for 32.57 NTD. Your assignment is to write a program to calculate the amount that a customer needs to pay for buying a specific amount of USD. The program prompts for the amount of USD the customer needs initially. After getting the number (which can have two digits after the decimal point), it will calculate the total amount the customer needs to pay which includes 100 NTD service fee. That is, if x is the amount the customer needs to pay for buying y USD, then

x = 32:57 y + 100


Typical program inputs and outputs are shown below.

  • a.out

Amount of USD to buy: 100

Total needs to pay: 3357.00

  • a.out

Amount of USD to buy: 2000

Total needs to pay: 65240.00


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

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

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

/* EE231002 Lab01 Currency Exchange ID, Name



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

$ gcc lab01.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 lab01 lab01.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 lab01

It will show the submission records for lab01.

  1. The objectives of this lab are:

7.1. Practice login and out of the EE workstations,

7.2. Practice simple linux commands,

7.3. Practice vim editor,

7.4. Practice writing simple C programs,

7.5. Practice compiling and executing C programs.

  1. (Challenge 1) Write a program is is capable of buying and selling USD.

  1. (Challenge 2) Since the smallest denomination of NTD is 1 dollar, modify your program to output NTD in integer amount, which is always round up of the total needed.

  1. These challenges are for your own practice, no need to turn them in.