Objectives

Specifications

You are to write a program that can convert values between three different currencies: Canadian Dollar, Japanese Yen and the Euro. When the program is started, the user is asked to enter the "source" and "destination" currencies, as well as the value to be converted. The program then performs the requested conversion and displays the result.

If the user enters a currency that is not recognized by the program, an error message should be displayed and the program should exit.

INPUT:

There are three inputs:

1. The source currency. This is the currency to be converted from, and can be one of three characters: '$' (Canadian Dollar), 'Y' (Japanese Yen) or 'E' (Euro).
2. The destination currency. This is the currency to be converted to, and must be one of the same three characters as for the source currency.
3. The source value. This is a floating-point number that is the amount of the source currency to be converted.

OUTPUT:

There are two possible outputs:

1. A statement showing the source and destination currencies and values, if there are no errors. Values should be rounded to 2 decimal places; or
2. A statement that an error occured, if the source and/or destination currency symbols were invalid.

EXCHANGE RATES:

Please use only these exchange rates (so the marking script can know the expected result precisely):

1 Canadian Dollar = 0.69 Euro
1 Canadian Dollar = 116.00 Yen
1 Euro = 166.60 Yen

USE OF SWITCH:

You must use a switch statement to determine the source currency and act accordingly. You are free to use "if" or "switch" to determine the destination currency.

USE OF A SUCCESS FLAG:

You must make use of a boolean variable to determine if an error occurred. Set this variable to 1 (i.e. "true") when the program starts, and change it to 0 (i.e. "false") if you encounter an invalid currency symbol. At the end of your switch, use an "if" statement to test this variable (called a "flag") to determine which output to give (the conversion or the error message).

SAMPLE:

Below are several samples showing the format of the prompts and the output. Please pay careful attention to the details and ensure your program behaves exactly the same.

Example 1: Convert Dollar to Yen

$ ./lab2.exe
Enter the source currency: $
Enter the destination currency: Y
Enter the value: 325.00
$325.00 = Y37700.00
$

Example 2: Convert Yen to Euro

$ ./lab2.exe
Enter the source currency: Y
Enter the destination currency: E
Enter the value: 12345.67
Y12345.67 = E74.10
$

Example 3: Error: invalid currency symbol

$ ./lab2.exe
Enter the source currency: A
Enter the destination currency: $
Enter the value: 123.45
There was an error with the input.
$

OTHER ERROR CONDITIONS:

You do not have to deal with error conditions other than entering an invalid currency symbol. In particular, you may assume the user will type one character for each currency. You may also assume the user enters a valid floating-point number for the source value.

REMEMBER!!!! Make your prompts and outputs look EXACTLY like my examples above!

Hints

Handing In

You are to email your source code file only to rthorndy@gmail.com with the subject header: "COMP 166 Lab 2 Submission". This file is due by Wednesday, January 28 at 3:30pm (before your next lab).

Marking

The lab will be marked out of 10 points:

2 points: Gives correct values for conversions
2 points: Catches input errors (i.e. invalid currency symbols)
2 points: Uses "switch" properly and as specified
2 points: Uses the "success" flag properly and as specified
2 points: format of prompts and output statement as specified