Question

In: Computer Science

2. Create a C++ program that converts the number of American dollars entered by the user...

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.

Solutions

Expert Solution

#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:


Related Solutions

Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Write a program that converts the user's number into the desired unit of measurement. The user...
Write a program that converts the user's number into the desired unit of measurement. The user will pick the desired unit from a menu shown below. Ask the follow-up question (the number to convert) and do the math ONLY if the user picks a valid choice from the menu. You can see the conversions / multipliers needed for this program in the output section below. Menu/Prompt: Enter the number that corresponds to your desired unit conversion from the choices below:...
Conversion of numeral to roman number: Create a FLOWCHART and C++ PROGRAM that prompts the user...
Conversion of numeral to roman number: Create a FLOWCHART and C++ PROGRAM that prompts the user to enter a number (from 1-3000 only) then output the number and its corresponding roman numeral number. ***validate the input (it must be 1-3000 only) SAMPLE OUTPUT: Enter a Number: 0 Number should be from 1-3000 only (Terminated) Enter a Number: -5 Number should be from 1-3000 only (Terminated) Enter a Number: 3500 Number should be from 1-3000 only (Terminated) Enter a Number: 1994...
Time Calculator Create a C++ program that lets the user enter a number of seconds and...
Time Calculator Create a C++ program that lets the user enter a number of seconds and produces output according to the following criteria: • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or...
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of...
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. One gram of fat has 9 calories, so: Calories from fat = fat grams *...
This is C++ Create a program that reads an HTML file and converts it to plain...
This is C++ Create a program that reads an HTML file and converts it to plain text. Console: HTML Converter Grocery List * Eggs * Milk * Butter Specifications: The HTML file named groceries.html contains these HTML tags: <h1>Grocery List</h1> <ul> <li>Eggs</li> <li>Milk</li> <li>Butter</li> </ul> When the program starts, it should read the contents of the file, remove the HTML tags, remove any spaces to the left of the tags, add asterisks (*) before the list items, and display the...
c ++ program that converts from any base to a decimal number
c ++ program that converts from any base to a decimal number
2. Write a program C++ that asks the user for a number (not necessary to force...
2. Write a program C++ that asks the user for a number (not necessary to force any particular requirements). Write a function with the following signature: double square(double x) that returns the square of the user's number (x * x). 3. Write a C++ program that asks the user for an integer. Write a function that returns 1 of the number is even, and 0 if the number is odd. Use this function signature: int isEven(int x). 4. Write a...
Write a program that allows the user to search the array to find the number entered
Write a program that allows the user to search the array to find the number entered
Write a program in C++ that converts a positive integer into the Roman number system. The...
Write a program in C++ that converts a positive integer into the Roman number system. The Roman number system has digits I      1 V    5 X    10 L     50 C     100 D    500 M    1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (3) The numbers 1 to 9 are expressed as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT