First time with Functions

So Im having trouble with this function. when I try and use this function it gives me an error. I cant figure out what Im doing wrong, this is my first time working with functions so I imagine its a simple error. Any help is appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
double userinput(double a1); // declaration

	double q = userinput(a1); //use 1 (This is where my error is occurring 'a1 is undeclared') 
	double w = userinput(a1); // use 2 (This is where my error is occurring)
	double e = userinput(a1); // use 3 (This is where my error is occurring)

double userinput(double a1) {                          // function code
	string a;
	cout << "Please enter center coordinate: ";
	cin >> a;
	a1 = stof(a);

	return a1;
}
double userinput(double); Prototypes need only the type, not the variable name.

You declare a1 a double when you send it to your function, but you don't use the variable at all.
What happens when you send it with no parameters?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
double userinput(double a1); // declaration

	double q = userinput(); //use 1 (This is where my error is occurring 'a1 is undeclared') 
	double w = userinput(); // use 2 (This is where my error is occurring)
	double e = userinput(); // use 3 (This is where my error is occurring)

double userinput() {                          // function code
	string a;
	cout << "Please enter center coordinate: ";
	cin >> a;
	a1 = stof(a);

	return a1;
}
closed account (48T7M4Gy)
You have to declare a1.

That means you need a statement before calling the function something like
double a1 = 5.432; and that needs to be in main() probably.

The point being, how can your computer be expected to know what a1 is if you don't tell it? :)

closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/177496/

Don't double post!!
it gives me an error "userinput function does not take 0 arguments"
Topic archived. No new replies allowed.