Assignment #3 - Practice with Loops & Functions

Due: Monday Feb 12th at 11:59:00pm

Objective

This assignment will consist of writing different small programs that involve practice utilizing loops and writing and calling functions. The second part of the vassignment will be the only one that will require the use of a function.

Task

Write the following programs, each in a separate file. Filenames should be: (Note that the filenames are all lowercase)

Exercise 1

Filename: numbers.cpp

Write a program that will allow the user to enter a set of integers (as many as they want), then prints out a summary of information, as follows:

Sample Runs

(user input is underlined, to distinguish it from output)

Sample Run 1

  Enter a Number (0 to stop): 12
  Enter a Number (0 to stop): 4
  Enter a Number (0 to stop): -1
  Enter a Number (0 to stop): -5
  Enter a Number (0 to stop): 18
  Enter a Number (0 to stop): 0

  # of positives = 3
  # of negatives = 2
  Sum = 28
  Average = 5.60

Sample Run 2

  Enter a Number (0 to stop): 4
  Enter a Number (0 to stop): 8
  Enter a Number (0 to stop): 24
  Enter a Number (0 to stop): 94
  Enter a Number (0 to stop): -1
  Enter a Number (0 to stop): 43
  Enter a Number (0 to stop): 13
  Enter a Number (0 to stop): 0

  # of positives = 6
  # of negatives = 1
  Sum = 185
  Average = 26.43

Sample Run 3

  Enter a Number (0 to stop): 0

  # of positives = 0
  # of negatives = 0
  Sum = 0
  Average = 0.00

Exercise 2

Filename: currency.cpp
  1. Write a function called toUSD that takes in two parameters, one double representing an amount of money in a foreign currency and a character representing the foreign currency you're converting from. The function will compute and return the amount of money in US Dollars as a double. Declare three const double variables inside this function to represent POUND EURO and YEN conversion rates (see #5) and use these variables in your calculations. The character parameter taken in by the function will either be P for Pounds, Y for Yen, or E for euros. Allow both uppercase and lowercase P, Y, and E to represent pounds, euros, and yen. This is all this function should do. NO user input or output to the screen should occur in this function.
     
  2. Write a function named menu() that takes in no parameters and returns no value. This function will simply be called anytime the following menu needs to be printed:
    Please select one of the following options:
    1 - Convert foreign Amount to USD
    2 - Add foreign amounts
    0 - Quit
    -----------------------------------
    
    Printing the menu is all that this function should do. No more, no less.

  3. To test these functions, write a main() routine (in the same file) that first welcomes the user and then enters a loop in which they are presented with the menu. They will select either 1, 2, or 0.





  4. ERROR CHECKING: You must implement error checking on the following situations: When the user enters an invalid menu option (some integer value other than 1,2, or 0), display an error message as seen in the sample runs. Also, if a negative amount is entered at any time, display an error message as seen in the sample runs. You may ASSUME that the user enters a correct character for Yen, Pounds, and Euros when prompted, and you may assume the user will enter the correct type of data at all times (aka, they wont enter a char when they're prompted for the menu option or for an amount for instance).

  5. Assume the conversion rates are as follows: $1 USD is equal to: .71 Pounds, .8 Euros, and 110.05 Yen (conversion rates as of 2/2/18)

Sample Run 1:

(user input underlined)
	
Welcome to the currency exchange calculator!
Please select one of the following options:
1 - Convert foreign Amount to USD
2 - Add foreign amounts
0 - Quit
-----------------------------------
> 1
What amount would you like to convert? > 45.67
Which currency would you like to convert to USD?        
P - Pound       E - Euro        Y - Yen
> P
45.67 Pounds converts to 64.32 US Dollars.

Please select one of the following options:
1 - Convert foreign Amount to USD
2 - Add foreign amounts
0 - Quit
-----------------------------------
> 2
Enter type of first currency    P - Pound       E - Euro        Y - Yen
> e
Enter amount of first currency
> 3.00
Enter type of second currency    P - Pound       E - Euro        Y - Yen
> P
Enter amount of second currency
> 3.00
This would equal 7.98 US dollars

Please select one of the following options:
1 - Convert foreign Amount to USD
2 - Add foreign amounts
0 - Quit
-----------------------------------
> 0
Goodbye!

Sample Run 2:

(user input underlined)
Welcome to the currency exchange calculator!
Please select one of the following options:
1 - Convert foreign Amount to USD
2 - Add foreign amounts
0 - Quit
-----------------------------------
> 5
Invalid selection. Try again.

Please select one of the following options:
1 - Convert foreign Amount to USD
2 - Add foreign amounts
0 - Quit
-----------------------------------
> 0
Goodbye!


Sample Run 3:

(user input underlined)
Welcome to the currency exchange calculator!
Please select one of the following options:
1 - Convert foreign Amount to USD
2 - Add foreign amounts
0 - Quit
-----------------------------------
> 1
What amount would you like to convert? > -876.5
Invalid amount entered. Amount must be non-negative.

Please select one of the following options:
1 - Convert foreign Amount to USD
2 - Add foreign amounts
0 - Quit
-----------------------------------
> 0
Goodbye!


Sample Run 4:

(user input underlined)
Please select one of the following options:
1 - Convert foreign Amount to USD
2 - Add foreign amounts
0 - Quit
-----------------------------------
> 2
Enter type of first currency    P - Pound       E - Euro        Y - Yen
> e
Enter amount of first currency
> -8.09      
Enter type of second currency    P - Pound       E - Euro        Y - Yen
> p  
Enter amount of second currency
> 98.3  
Invalid amount entered. Amounts must be non-negative.

Please select one of the following options:
1 - Convert foreign Amount to USD
2 - Add foreign amounts
0 - Quit
-----------------------------------
> 0
Goodbye!

Requirements for all programs


Submitting:

Program submissions should be done through canvas. Submit the files:
 numbers.cpp
 currency.cpp
in ONE canvas submission