0

If/Else Statements

I'm trying to use if/else statements with the discriminant formula, b^2-4ac to print out the number of solutions and to print out the actual answers. rootCount in my main is saying that rootCount needs a pointer-to. #include<iostream> #include<string> using namespace std; double rootCount(double a, double b, double c); double d1(double a, double b, double c); double d2(double a, double b, double c); int main(void) { double a, b, c, d; double rootCount; cout << "Program uses the discriminant, b^2-4ac, to determine the number and type of roots." << endl; cout << "Enter a: "; cin >> a; cout << "Enter b: "; cin >> b; cout << "Eneter c: "; cin >> c; d = b * b - 4 * a * c; cout << "The number of solutions is: " << rootCount(a, b, c ) << endl; cout << "The solutions are: " << d1(a, b, c) << "and " << d2(a, b, c) << endl; system("pause"); return 0; } double rootCount (double a, double b, double c) { double d; d = b * b - 4 * a * c; if (d > 0) { cout << "Two solutions" << endl; } if (d == 0) { cout << "One solution" << endl; } else { cout << "No real solutions" << endl; } return d; } double d1(double a, double b, double c) { double d; d=(b*b - 4 * a*c); return d; } double d2 (double a, double b, double c) { double d; d= -1 * (b*b - 4*a*c); return d; }

6th Sep 2018, 9:40 PM
Krista Clark
Krista Clark - avatar
4 odpowiedzi
0
Now I can actually run the program. When I run the program though, the program prints one of the if statements and the else statement. Also it will say "the number of solutions is: 28." When I really want that number to be printed in "The solutions are: 28 and -28"
6th Sep 2018, 10:24 PM
Krista Clark
Krista Clark - avatar
0
I put my if else statements in the main function and it fixed my problem. Thanks for the help.
7th Sep 2018, 7:11 AM
Krista Clark
Krista Clark - avatar