Calculations not working correctly

I am having trouble with this program. It runs fine but the calculations in two of my functions are not working correctly: convertToPesos and convertToYen

My apologies if I did not correctly format my code!

<#include <iostream>
#include <iomanip>
using namespace std;

// Prototypes of the functions
void convertMulti(float dollars, float& euros, float& pesos);
void convertMulti(float dollars, float& euros, float& pesos, float& yen);
float convertToYen(float dollars, float yen); float convertToEuros(float dollars, float& euros); float convertToPesos(float dollars, float pesos);
int main()
{
float dollars = 0; float euros = 0; float pesos = 0; float yen = 0;
cout << fixed << showpoint << setprecision(2);
cout << "Please input the amount of American Dollars you want converted "
<< endl;
cout << "to euros and pesos" << endl;
cin >> dollars;
// Fill in the code to call convertMulti with parameters dollars, euros, and pesos
convertMulti(dollars, euros, pesos);
// Fill in the code to output the value of those dollars converted to both euros
// and pesos
cout << dollars << " is converted to $" << euros << " euros and $" << pesos << " pesos." << endl << endl;

cout << "Please input the amount of American Dollars you want converted\n";
cout << "to euros, pesos and yen" << endl;
cin >> dollars;
// Fill in the code to call convertMulti with parameters dollars, euros, pesos and yen
convertMulti(dollars, euros, pesos, yen);
// Fill in the code to output the value of those dollars converted to euros,
// pesos and yen
cout << dollars << " is converted to $" << euros << " euros and $" << pesos << " pesos and $" << yen << " yen." << endl << endl;

cout << "Please input the amount of American Dollars you want converted\n";
cout << "to yen" << endl;
cin >> dollars;
// Fill in the code to call convertToYen
convertToYen(dollars, yen);
// Fill in the code to output the value of those dollars converted to yen
cout << dollars << " is converted to $" << yen << " yen." << endl << endl;

cout << "Please input the amount of American Dollars you want converted\n";
cout << " to euros" << endl;
cin >> dollars;
// Fill in the code to call convert ToEuros
convertToEuros(dollars, euros);
cout << dollars << " is converted to $" << euros << " euros." << endl << endl;

// Fill in the code to output the value of those dollars converted to euros
cout << "Please input the amount of American Dollars you want converted\n";
cout << " to pesos " << endl;
cin >> dollars;

// Fill in the code to call convertToPesos
convertToPesos(dollars, pesos);
cout << dollars << " is converted to $" << pesos << " pesos." << endl << endl;

// Fill in the code to output the value of those dollars converted to pesos
system("pause");
return 0;
}
// All of the functions are stubs that just serve to test the functions
// Replace with code that will cause the functions to execute properly
// **************************************************************************
// convertMulti
//
// task: This function takes a dollar value and converts it to euros
// and pesos
// data in: dollars
// data out: euros and pesos
//
// *************************************************************************
void convertMulti(float dollars, float& euros, float& pesos)
{
euros = dollars * 1.06;
pesos = dollars * 9.73;

}

// ************************************************************************
// convertMulti
//
// task: This function takes a dollar value and converts it to euros
// pesos and yen
// data in: dollars
// data out: euros pesos yen
//
// ***********************************************************************
void convertMulti(float dollars, float& euros, float& pesos, float& yen)
{
euros = dollars * 1.06;
pesos = dollars * 9.73;
yen = dollars * 124.35;
}
// ****************************************************************************
// convertToYen
//
// task: This function takes a dollar value and converts it to yen
// data in: dollars
// data returned: yen
//
// ***************************************************************************
float convertToYen(float dollars, float yen)
{
yen = dollars * 124.35;

return 0;
}
// ****************************************************************************
// convertToEuros
//
// task: This function takes a dollar value and converts it to euros
// data in: dollars
// data returned: euros
//
// ***************************************************************************
float convertToEuros(float dollars, float& euros)
{
euros = dollars * 1.06;

return 0;
}
// *****************************************************************************
// convertToPesos
//
// task: This function takes a dollar value and converts it to pesos
// data in: dollars
// data returned: pesos
//
// ****************************************************************************
float convertToPesos(float dollars, float pesos)
{
pesos = dollars * 9.73;

return 0;
}>
Last edited on
convertToPesos and convertToYen


1
2
3
4
5
6
float convertToYen(float dollars, float yen)
{
    yen = dollars * 124.35;

    return 0;
}
This is falling between two stools, as it were.

Either pass the parameter you want to change by reference, and don't try to return anything, like this:
1
2
3
4
void convertToYen(float dollars, float &yen)
{
    yen = dollars * 124.35;
}


Or just pass a single parameter, and return the required result, like this:
1
2
3
4
float convertToYen(float dollars)
{
    return dollars * 124.35;
}


See tutorial on functions:
http://www.cplusplus.com/doc/tutorial/functions/
Last edited on
Thank you! That fixed it....
If this Topic is completed, then please mark it as solved please.
Topic archived. No new replies allowed.