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;
}