hi there everyone~~ please check my error :)

hi there everyone. i'm learning how to use functions and i'm not sure what my mistake is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
using namespace std;
double get_coin(double c);
int main()
{
        double coin ;
        coin = get_coin() ;

return 0;
}

double get_coin(double c)
{
        double coin ;   
             cout << "Cost of a fried twinkie is $3.50\n"
                  << "--------------------------------\n"
                  << "Please enter coin: $";
             cin  >> coin ;
             return coin ;
}



chap4pp15.cpp: In function ‘int main()’:
chap4pp15.cpp:9:25: error: too few arguments to function ‘double get_coin(double)’
coin = get_coin() ;
^
chap4pp15.cpp:4:8: note: declared here
double get_coin(double c);
closed account (10X9216C)
 
coin = get_coin(0.0);


The declaration of get_coin requires a double be passed as a parameter.
Don't mean to be a dick or anything but the error is pretty straight forward
chap4pp15.cpp:9:25: error: too few arguments to function ‘double get_coin(double)’
coin = get_coin() ;
Basically, your function prototype has a parameter of a double and you call the function with zero parameters. It should be coin = get_coin(coin);

Also, in your function line 14 is not needed, line 18 should be cin >> c; and I would remove line 19 and pass by reference or change it to return c; currently I see no purpose of having a parameter to pass unless you want to pass it as a reference (&). To do it the way you are currently I would change the prototype and declaration to double get_coin(void); or double get_coin(); and leave the rest of the function how it is.
thank you myesolar ><
giblit i understand what you mean about not creating another double and using the parameter already made. really good stuff :P
if I understood what this function does then the function protoype is wrong and should be:
double get_coin(); //no parameters
the body remains the same
Topic archived. No new replies allowed.