Need help with functions

Sep 21, 2015 at 5:43am
Ive written these functions but I need a little more descriptive help with the last one
-getDollars: a function that returns the amount in U.S. dollars entered by the user. This function will return a double value. This function is the same as in Part 1.

-usToNZD : a function that takes the amount of U.S. dollars as a parameter and returns the amount in New Zealand dollars. This function will return a double value.

-usToGBP: a function that takes the amount of U.S. dollars as a parameter and returns the amount in British pounds. This function will return a double value.

-usToEuro: a function that takes the amount of U.S. dollars as a parameter and returns the amount in Euros. This function will return a double value.

-printConvertedDollars: a function that takes the US. dollar amount as a parameter, calls the three conversion functions, and prints out the converted amounts.
-------------------------------------------------------------------------------

double getDollars(string text)
{
double USDol;
cout << text << " ";
cin >> USDol;

return USDol;
}

double usToNZD(double value, double getDollars)
{
double usNZ;
usNZ = (value * getDollars);

return usNZ;
}
double usToGBP(double value, double getDollars)
{
double usGBP;
usGBP = (value * getDollars);

return usGBP;
}
double usToEuro(double value, double getDollars)
{
double usEU;
usEU = (value * getDollars);

return usEU;
}

void printConvertedDollars(double value, double getDollars) //This is the one I need to change //
{
cout << fixed << setprecision(2);
cout << (value * getDollars);
}
Sep 21, 2015 at 7:03am
I don't understand the getDollars parameter. I think all your functions should only have one parameter.

The instructions are telling you to use the three usTo functions that you have written above and print the return values.
Last edited on Sep 21, 2015 at 7:04am
Sep 21, 2015 at 7:24am
the getDollars parameter will print the text written in the () when it is used in the main function

ex. dollarsUS = getDollars("Enter an amount in US Dollars:");
cout << endl;

it would print out the text then ask for an input.
ex. Enter an amount in US Dollars: *user input*

I just got really lost with the printConvertedDollars function

Sep 21, 2015 at 7:37am
You don't want to pass getDollars() as a parameter to usToNZD(), usToGBP, and usToGBP. Instead, you want to call getDollars(), and pass the result to these functions. In other words, your main program might look like this:

1
2
3
4
5
int main()
{
   double usd = getDollars("Enter amount in $USD:");
   printConvertDollars(usd);
}
Sep 21, 2015 at 7:42am
I didn't mean the getDollars function. I was talking about your other functions that all has a second parameter named getDollars.

For some reason I forgot to mention that my second line was talking about the printConvertedDollars. What I was trying to say was that the printConvertedDollars function should call the three functions usToNZD, usToGBP, usToEuro, and print the values they return. That's what the instructions tell you do do.
Topic archived. No new replies allowed.