When a function is defined, you have to specify the types of the arguments, as you correctly did.
|
double convert( double amount, double usd, double rm)
|
this means you have a function named convert that will return a double and will take 3 doubles as arguments, which will be named amount, usd and rm INSIDE the function.
But when it is CALLED you don't have to specify the type again:
1 2
|
convert(15, 20, 32); //this is a valid call
double result = convert(15, 20, 32); //this is a call that saves the result inside a variable named result.
|
The point is you are missing basics here. The "answer" of a function is your return value, so it doesn't have to be in the signature.
Correct:
1 2 3 4
|
double convert( double amount, double usd)
{
return(amount*usd);
}
|
Also note, you seem to think you return the variable, since you later use "rm" in the main. It's not like that. The variables in the signature and in the function exist only inside the function, their "names" have no meaning outside.
Hence, you have to assign the VALUE returned by your function, to a new variable in the place you call said function.
1 2 3 4 5 6 7 8 9
|
int main()
{
double rm, amount;
const double usd = 4.0;
cin >> amount;
rm = convert(amount, usd);
cout << "RM: " << rm << endl;
}
|
Even if you created a variable named "rm" inside your function, it wouldn't change anything in your main. You have to assign the return value of the function to something in your main.
There are ways to do it in another way, but since you seem to be missing the basics i don't want to give you even more troubles understanding.
You might want to do some search about
variables scoping in c++ (which is the same in most languages anyway)