In quadratic equation ax^2 + bx + c, there are two possible values for x. These lines of code set the values of x to both of the possible values. However, these lines do not work, and it always yields the error message: expected ')' before ';' token
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
double a, b, c, x1, x2;
char cont('y');
cout << "Enter the values of a, b, and c in the equation ax^2 + bx + c = 0.\n";
cout << "I will tell you all possible values of x.\n";
do
{
cout << "a = ";
cin >> a;
//Tells the user that 'a' cannot be 0 and asks for it again
while (a == 0)
{cout << endl << "If a = 0, then it is not a quadratic formula.\nPlease enter another value.\n";
cout << "\na = ";
cin >> a;}
cout << a;
cout << "b = ";
cin >> b;
cout << b;
cout << "c = ";
cin >> c;
cout << c;
if (b * b - 4 * a * c < 0) //In case the problem has no solutions
{cout << "This equation has no solutions.\n";
break;}
cout << endl << "The equation will be " << a << "x^2 + " << b << "x + " << c << " = 0.\n";
x1 = (-b + sqrt(pow(b, 2.0) - 4 * a * c) / (2 * a);//Plus squareroot for x1
x2 = (-b - sqrt(pow(b, 2.0) - 4 * a * c) / (2 * a);//Minus squareroot for x2
cout << endl << "The two possible values of x are " << x1 << " and " << x2 << ".\n";
cout << "Do you want to continue (y or n)? ";
cin >> cont;
}while (cont == 'y' || cont == 'Y');
cout << endl << endl << endl;
system("pause");
return 0;
}
I should note that I am just beginning to use the #include <cmath> library.