Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Thanks! Write function called tous that takes in one double representing an amou

ID: 3792545 • Letter: T

Question


Thanks! Write function called tous that takes in 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 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. Both uppercase and lowercase P, Y, and Eto represent pounds, euros, and yen. NO user input or output to the screen should occur in this function Write a function named oueou 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 teteigu Amount to USD 2 -Add foreign amounts. Printing the menu is all that this function should do 1. To test these functions, write a waiR0 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. If they select1. they will be converting a foreign currency to USD. Ask for the amount they'd like to convert, then ask for a character representing the currency they're converting from or Eie Yen, Pounds, or Euros) allowing both uppercase and lowercase letter entries. Pass these values to your30USD function to help to display the amount in USD If the user selects 2 on the menu, they will be adding two amounts in different currencies together to get one value in USD. Prompt them for the type of the first currency and the amount of the first currency, and the type and amount of the second currency. Then, display the first currency amount the second currency amount in USD to the screen. You'll call your to USD0 function twice here to help with this If the user selects 0, allow the program to exit. They will be prompted for a menu entry as long as they enter other values besides 0. Only upon entering 0 should the program quit. If the user selects something other than 1,2, or 0, you must print an error message. 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 Also, if a negative amount is entered at any time, display an error message. 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 foran amount for instance). Rates to use: $1 USD is equal to: .86 Pounds, .96 Euros, and 112.56Yen

Explanation / Answer

#include <iostream>
using namespace std;

double toUSD(double amount,char currency) //function to convert currency to usd
{
   const double POUND = 1.0/0.86;   //constants
   const double EURO = 1.0/0.96;
   const double YEN = 1.0/112.56;
  
   if(currency == 'P' || currency == 'p')
   return (POUND * amount);
   else if(currency == 'E' || currency == 'e')
   return (EURO * amount);
   else if(currency == 'Y' || currency == 'y')
   return (YEN * amount);
   else
   return 0;
  
}

void menu()    //meny display function
{
   cout<<" Please select one of the following options :";
   cout<<" 1 - Convert foreign Amount to USD.";
   cout<<" 2 - Add Foreign Amounts.";
   cout<<" 0 - Quit";
  
}
int main()
{
   int option =0;
   double amount;
   double sum =0;
   char currency;
  
   do   //loop for currency converter
   {
   cout<<" Welcome to the currency exchange calculator!";
   menu();
   cin>>option;
   switch(option)
   {
       case 1: cout<<" what amount would you like to convert ?";
               cin>>amount;
               cout<<" Which currency would you like to convert to USD?";
               cout<<" P - Pound     E - Euro   Y - Yen";
               cin>>currency;
               cout<<" "<<amount<<" "<<currency<<" converts to "<<toUSD(amount,currency)<<" US Dollars.";
               break;
       case 2: cout<<" Enter type of first currency P - Pound     E - Euro   Y - Yen";
               cin>>currency;
               cout<<" Enter amount of first currency";
               cin>>amount;
               sum = toUSD(amount,currency);
               cout<<" Enter type of second currency P - Pound     E - Euro   Y - Yen";
               cin>>currency;
               cout<<" Enter amount of second currency";
               cin>>amount;
               sum = sum + toUSD(amount,currency);
               cout<<" This would equal to "<<sum<<" US dollars";
                 break;
       case 0: cout<<" GoodBye!";
               break;
   }
  
   }while(option != 0);
   return 0;
}

output:

Dr Jack
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote