What am I doing wrong writing function properly

I need help writing this function properly.

double getA();

This function will get and return the a-coefficient of the parabola. It takes no arguments and returns a double: the valid a-coefficient.

The function should display a prompt to the user and accept a value. If the value the user enters is non-zero, it should be returned to the calling function. If the value the user enters is 0, display an error message that the a-coefficient must be non-zero and ask the user to re-enter the value. This should be repeated until non-zero value is entered.

I got this so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
double getA();
cout << "Enter the a coefficient (non -zero value:\n";
cin >> aCoeff;

while (aCoeff >0)
	{
	cout << "Error: The a-value MUST be non-zero. Try Again:";
	cin >> aCoeff;
	} 
cout << "Enter the b coefficient: ";
cin >> bCoeff;
  
cout << "Enter the c coefficient: ";
cin >> cCoeff;
your while condition executes, if the user enters an value greater than zero. So u always get error message unless user enter a value less than or equal to zero.
so change condition accordingly.

ur function for getA should be like this
1
2
3
4
5
6
double getA()
{
  insert Line 2 to line 9 here
  return aCoeff;
}
thank you vichu8888 for the help
Topic archived. No new replies allowed.