// This program will input American money and convert it to foreign currency #in
ID: 655520 • Letter: #
Question
// This program will input American money and convert it to foreign currency
#include <iostream>
#include <iomanip>
using namespace std;
/* ADD code for function prototypes */
int main ()
{
float dollars;
float euros;
float yens;
cout << fixed << showpoint << setprecision(2);
cout << "Please input the amount of American Dollars you want converted " << endl; cout << "to euros and yen" << endl;
cin >> dollars;
// Fill in the code to call currency coversion functions
//Write output statment(s) to display values in dollar, euro, and yen on same line
system("pause");
return 0;
}
float convertToYen(float dollars)
// Task: This function takes a dollar value and converts it to yens
// Data in: dollars // Data out: none
// Data returned: equivalent value in yens
{
cout << "The function convertToYen was called with " << dollars <<" dollars" << endl << endl;
/* FILL IN code to convert value in parameter dollars from dollar to yen. Lookup exchange rate on the Internet */
/* Add code to return value */
}
float convertToEuros(float dollars)
// Task: This function takes a dollar value and converts it to euros
// Data in: dollars
// Data out:
// Data returned: equivalent value in euros
{
cout << "The function convertToEuros was called with " << dollars << " dollars" << endl << endl;
/* FILL IN code to convert value in parameter dollars from dollar to yen. Lookup exchange rate on the Internet */
/* Add code to return value */
}
Exercise 1. Complete the code for the above program. Execute it with the following input:
Value in $: 0 100 235.56
Exercise 2. Modify program so that it also converts the input value in dollars to pesos.
Explanation / Answer
Program :
// This program will input American money and convert it to foreign currency
#include <iostream>
#include <iomanip>
using namespace std;
/* ADD code for function prototypes */
float convertToYen(float dollars);
float convertToEuros(float dollars);
int main (void)
{
float dollars;
float euros;
float yens;
cout << fixed << showpoint << setprecision(2);
cout << "Please input the amount of American Dollars you want converted " << endl; cout << "to euros and yen" << endl;
cin >> dollars;
// Fill in the code to call currency coversion functions
yens= convertToYen(dollars);
euros=convertToEuros(dollars);
//Write output statment(s) to display values in dollar, euro, and yen on same line
cout<<dollars<<" "<<euros<<" "<<yens<<endl;
system("pause");
return 0;
}
// Task: This function takes a dollar value and converts it to yens
// Data in: dollars // Data out: none
float convertToYen(float dollars){
/* FILL IN code to convert value in parameter dollars from dollar to yen. Lookup exchange rate on the Internet */
float y=119.19;
y=dollars*y;
cout << "The function convertToYen was called with " << dollars <<" dollars" << endl << endl;
/* Add code to return value */
// Data returned: equivalent value in yens
return y;
}
// Task: This function takes a dollar value and converts it to euros
// Data in: dollars
// Data out:
float convertToEuros(float dollars){
// Data returned: equivalent value in euros
float eu=0.92;
/* FILL IN code to convert value in parameter dollars from dollar to yen. Lookup exchange rate on the Internet */
eu=dollars*eu;
cout << "The function convertToEuros was called with " << dollars << " dollars" << endl << endl;
/* Add code to return value */
return eu;
}
Expected Output 1:
Please input the amount of American Dollars you want converted
to euros and yen
0
The function convertToYen was called with 0.00 dollars
The function convertToEuros was called with 0.00 dollars
0.00 0.00 0.00
Press any key to continue . . .
Expected Output :
Please input the amount of American Dollars you want converted
to euros and yen
100
The function convertToYen was called with 100.00 dollars
The function convertToEuros was called with 100.00 dollars
100.00 92.00 11919.00
Press any key to continue . . .
Expected Output 3:
Please input the amount of American Dollars you want converted
to euros and yen
235.56
The function convertToYen was called with 235.56 dollars
The function convertToEuros was called with 235.56 dollars
235.56 216.72 28076.40
Press any key to continue . . .
Program 2 :
// This program will input American money and convert it to foreign currency
#include <iostream>
#include <iomanip>
using namespace std;
/* ADD code for function prototypes */
float convertToYen(float dollars);
float convertToEuros(float dollars);
float convertToPesos(float dollars);
int main (void)
{
float dollars;
float euros;
float yens;
float pesos;
cout << fixed << showpoint << setprecision(2);
cout << "Please input the amount of American Dollars you want converted " << endl; cout << "to euros, yen and pesos" << endl;
cin >> dollars;
// Fill in the code to call currency coversion functions
yens= convertToYen(dollars);
euros=convertToEuros(dollars);
pesos=convertToPesos(dollars);
//Write output statment(s) to display values in dollar, euro, yen and peso on same line
cout<<dollars<<" "<<euros<<" "<<yens<<" "<<pesos<<endl;
system("pause");
return 0;
}
// Task: This function takes a dollar value and converts it to yens
// Data in: dollars // Data out: none
float convertToYen(float dollars){
/* FILL IN code to convert value in parameter dollars from dollar to yen. Lookup exchange rate on the Internet */
float y=119.19;
y=dollars*y;
cout << "The function convertToYen was called with " << dollars <<" dollars" << endl << endl;
/* Add code to return value */
// Data returned: equivalent value in yens
return y;
}
// Task: This function takes a dollar value and converts it to euros
// Data in: dollars
// Data out:
float convertToEuros(float dollars){
// Data returned: equivalent value in euros
float eu=0.92;
/* FILL IN code to convert value in parameter dollars from dollar to yen. Lookup exchange rate on the Internet */
eu=dollars*eu;
cout << "The function convertToEuros was called with " << dollars << " dollars" << endl << endl;
/* Add code to return value */
return eu;
}
// Task: This function takes a dollar value and converts it to Pesos
// Data in: dollars
// Data out:
float convertToPesos(float dollars){
// Data returned: equivalent value in Pesos
float p=15.39;
/* FILL IN code to convert value in parameter dollars from dollar to yen. Lookup exchange rate on the Internet */
p=dollars*p;
cout << "The function convertToPesos was called with " << dollars << " dollars" << endl << endl;
/* Add code to return value */
return p;
}
Expected Output 1 :
Please input the amount of American Dollars you want converted
to euros, yen and pesos
0
The function convertToYen was called with 0.00 dollars
The function convertToEuros was called with 0.00 dollars
The function convertToPesos was called with 0.00 dollars
0.00 0.00 0.00 0.00
Press any key to continue . . .
Expected Output 2 :
Please input the amount of American Dollars you want converted
to euros, yen and pesos
100
The function convertToYen was called with 100.00 dollars
The function convertToEuros was called with 100.00 dollars
The function convertToPesos was called with 100.00 dollars
100.00 92.00 11919.00 1539.00
Press any key to continue . . .
Expected Output 3 :
Please input the amount of American Dollars you want converted
to euros, yen and pesos
235.56
The function convertToYen was called with 235.56 dollars
The function convertToEuros was called with 235.56 dollars
The function convertToPesos was called with 235.56 dollars
235.56 216.72 28076.40 3625.27
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.