There are two problems in your code.
Firstly, if you want to call your function
double moon_g (double a, double b) // this means if you want to call moon_g() you must provide arguments a and b, otherwise, the you will encounter an compile error.
{
cout<<"Enter the mass in kilograms. Use decimal point for any number entered";
cin>>a;
b=(17*9.8)/100;
double mg=a*b;
return mg;
}
you should provide the two parameters a
and b
.
But a
and b
are calculated in the body of function definition, it is unnecessary to declare the two parameters. You can write like this.
double moon_g () //this means function moon_g() does not accept any arguments
{
double a, b; // declare a and b in the definition body instead of in the arguments list
cout<<"Enter the mass in kilograms. Use decimal point for any number entered";
cin>>a;
b=(17*9.8)/100;
double mg=a*b;
return mg;
}
Then, in the main function, your calling function statement is wrong. You may want to receive the return value. So, you should write the code like this.
int main()
{
cout<<"This program will calculate the weight of any mass on the moon\n";
double ret = moon_g();
}
Finally, it is mostly recommended that the function which will be called by another function should be declared or defined previously.