In: Computer Science
2. Create a C++ program that converts the number of American dollars entered by the user into one of the following foreign currencies: Euro, British pound, German mark, or Swiss franc. Allow the user to select the foreign currency from a menu. Store the exchange rates in a four-element double array named rates. Notice that the menu choice is always one number more than the subscript of its corresponding rate. For example, menu choice 1's rate is stored in the array element whose subscript is 0. Below is the sample run of the program.
#include <iostream>
using namespace std;
int main()
{
//variable declaration
int choice;
double rates[] ={50, 70, 30, 40};
double amount, newCurAmount;
//get amount from the user
cout<<"Enter the amount: $";
cin>>amount;
//display menue
cout<<endl<<"1: Euro";
cout<<endl<<"2: British pound";
cout<<endl<<"3: German mark";
cout<<endl<<"4: Swiss franc";
cout<<endl<<endl<<"Enter your choice: ";
cin>>choice;
//calculate the new currency amount
if(choice == 1)
{
newCurAmount = amount * rates[0];
cout<<endl<<"The amount in Euro is:
"<<newCurAmount;
}
else if(choice == 2)
{
newCurAmount = amount * rates[1];
cout<<endl<<"The amount in British pound is:
"<<newCurAmount;
}
else if(choice == 3)
{
newCurAmount = amount * rates[2];
cout<<endl<<"The amount in German mark is:
"<<newCurAmount;
}
else if(choice == 4)
{
newCurAmount = amount * rates[3];
cout<<endl<<"The amount in Swiss franc is:
"<<newCurAmount;
}
else
{
cout<<endl<<"Invalid Input!";
}
return 0;
}
OUTPUT: