I tried the following:
A = 2 B = -4 C= -3
But it does not give me the following values:
x1 = –0.58, x2 = 2.58
#include <cmath> // includes all instrutions for CMATH
#include <iostream>
using namespace std;
int main()
{
long double A,B,C,DISC,X1,X2;
cout << "Welcome to the program quad, this program calculates the zeros in";
cout << endl;
cout << "a given function (ex. 1x^2+3x-4) by calculating the quadratic\n";
cout << "formula.";
cout << endl;
do // error Check loop
{
cout << "Please enter a value for A:";
cout << endl;
cout << "WARNING: A CAN NOT EQUAL 0";
cout << endl;
cin >> A;
cout << endl;
cout << "Please enter a value for B:";
cout << endl;
cin >> B;
cout << endl;
cout << "Please enter a value for C:";
cout << endl;
cin >> C;
cout << endl;
}while ((A <= 0)||(A == 0));
DISC = pow(B,2)-4*A*C;
if (DISC < 0)
{
cout << endl;
cout << "NO SOLUTIONS: IMAGINARY Awnser\n";
cout << endl;
}
else if (DISC == 0)
{
cout << endl;
cout << "1 Solution: "<< -1*B/2*A;
cout << endl;
}
else if (DISC > 0)
{
cout << endl;
cout << "2 solutions: "<<endl;
X1= -1 * B + sqrt(DISC) / 2 * A;
X2= -1 * B - sqrt(DISC) / 2 * A;
cout << endl;
cout << "solution 1 = " << X1;
cout << endl << endl;
cout << "solution 2 = " << X2;
}
cout << endl << endl << endl << endl << endl;
system ("pause");
return 0;
}
Please HELP!

New Topic/Question
Reply



MultiQuote



|