Lab 1 Odd and Even Week: More Currency Conversions

Deadlines

Submission opens on: Tuesday 08 February 2005, 00:00:00 hours.
The deadline for all groups (both odd and even week) is Wednesday 16 February 2005, 23:59:59 hours.

Your file must be named convert.c, incorrect filename will result in zero marks. This lab is worth five marks.

To submit your program, simply type submit convert.c at your sunfire prompt.

You are reminded to use the lab header that is found at the general information page. If you forget the lab header or fill it with incorrect information, marks may be deducted.


Overview

This question is an adaptation of a similar question found in Etter page 142, as well as questions 21 to 24 of Tutorial 3. The following conversion rates are assumed where S$, U$, E$, P$ denotes Singapore dollar, US Dollar, Euro, and Pound Sterling respectively.

Suppose a foreign tourist from USA, Europe, or Great Britain comes to Singapore and he wants to find out how much his currency is worth in Singapore dollars. Your job is to prompt the foreign tourist for the country he comes from, then generate conversion tables for his corresponding currency to Singapore dollars.

Your task for this lab assignment is as follows:

  1. Prompt the user for his home country.
  2. Prompt the user for the start, end, and interval for the currency table.
  3. Generate a corresponding table of conversions as specified by the user.

Program Specifications

Given the three conversions specified above, include the three corresponding #define directives in your program. The directives must be placed immediately after the #include directives.
    #define U2S 1.6397
    #define E2S 2.1351
    #define P2S 3.0903
Your program should begin by prompting the user to enter an integer to represent his home country according to the following country codes:

Assume that the user always enters a valid country code. Once the user enters a country code, display the exchange rate.

Then prompt the user for the following input. You may assume that the input are all integers.

Assume that the starting amount never exceeds the ending amount, and that all amounts and intervals are positive integers.

All floating-point numbers must be printed to four decimal places.

To assist in your coding, a series of sample output is shown in the next section. User input is denoted in bold print. You must follow the sample output precisely; failure to do so may result in loss of marks. Note especially that the user prompts change for different countries (U$, E$, or P$).

Sample Output

moneyFace@sf3:~/c[500]$ gcc -Wall convert.c -o convert
moneyFace@sf3:~/c[501]$ ./convert
Please enter the country you come from.
Enter 1 for USA.
Enter 2 for Europe.
Enter 3 for Great Britain.
1

Exchange rate: U$1 to S$1.6397

Starting from (U$):
20
Ending at (U$):
100
Interval (U$):
10

Printing Conversion Table...

        U$             S$
        20        32.7940
        30        49.1910
        40        65.5880
        50        81.9850
        60        98.3820
        70       114.7790
        80       131.1760
        90       147.5730
       100       163.9700

moneyFace@sf3:~/c[502]$ ./convert
Please enter the country you come from.
Enter 1 for USA.
Enter 2 for Europe.
Enter 3 for Great Britain.
3

Exchange rate: P$1 to S$3.0903

Starting from (P$):
100
Ending at (P$):
120
Interval (P$):
3

Printing Conversion Table...

        P$             S$
       100       309.0300
       103       318.3009
       106       327.5718
       109       336.8427
       112       346.1136
       115       355.3845
       118       364.6554

moneyFace@sf3:~/c[503]$ ./convert
Please enter the country you come from.
Enter 1 for USA.
Enter 2 for Europe.
Enter 3 for Great Britain.
2

Exchange rate: E$1 to S$2.1351

Starting from (E$):
1000000
Ending at (E$):
10000000
Interval (E$):
500000

Printing Conversion Table...

        E$             S$
   1000000   2135100.0000
   1500000   3202650.0000
   2000000   4270200.0000
   2500000   5337750.0000
   3000000   6405300.0000
   3500000   7472850.0000
   4000000   8540400.0000
   4500000   9607950.0000
   5000000  10675500.0000
   5500000  11743050.0000
   6000000  12810600.0000
   6500000  13878150.0000
   7000000  14945700.0000
   7500000  16013250.0000
   8000000  17080800.0000
   8500000  18148350.0000
   9000000  19215900.0000
   9500000  20283450.0000
  10000000  21351000.0000

moneyFace@sf3:~/c[504]$


This document, index.html, has been accessed 27 times since 25-Jun-24 11:57:13 +08. This is the 1st time it has been accessed today.

A total of 18 different hosts have accessed this document in the last 445 days; your host, 216.73.216.39, has accessed it 1 times.

If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.