6.7 - The return Statement
Write the definition of a function named quadratic that receives three double parameters a, b, c. If the value of a is 0 then the function prints the message "no solution for a=0" and returns. If the value of "b squared" - 4ac is negative, then the code prints out the message "no real solutions" and returns. Otherwise the function prints out the largest solution to the quadratic equation. The formula for the solutions to this equation can be found here: Quadratic Equation on Wikipedia.
double quadratic (double a, double b, double c) { double x; if (a==0) { cout << "no solution for a=0"; } else if ((b*b - 4*a*c) < 0) { cout << "no real solutions"; } else { x = (-b + sqrt( b*b - 4*a*c)) /(2*a); cout << x; } }
Given that a function receives three parameters a, b, c, of type double , write some code, to be included as part of the function, that determines whether the value of "b squared" - 4ac is negative. If negative, the code prints out the message "no real solutions" and returns from the function
if ((b*b - 4*a*c)<0) cout << "no real solutions";
Given that a function receives three parameters a, b, c, of type double , write some code, to be included as part of the function, that checks to see if the value of a is 0; if it is, the code prints the message "no solution for a=0" and returns from the function.
if (a == 0) {cout << "no solution for a=0; }
