I just started programming in c++ and i tried to explore and do programs on my own... So i wanted to do a program that would help me in my daily school work ... a program to solve quadratic equations.. I wrote the code correctly but errors are still detected and i have no idea why.. almost gave up and banged my head on the wall .. so i would really appreciate help.. This is the code so far..
-
#include <cmath>
-
#include <iostream>
-
-
using namespace std;
-
-
int main()
-
{
-
double x;
-
double y;
-
double z;
-
-
cout<<"Please enter the coeff of (x square):";
-
cin>> x;
-
cout<<"Please enter the coeff of (x):";
-
cin>> y;
-
cout<<"Please enter the number without the unknown (x):";
-
cin>> z;
-
-
double b = (((y * y) - (4 * x * z)));
-
double a = ((-y + (sqrt (b)) / (2 * x)));
-
double c = ((-y - (sqrt (b)) / (2 * x)));
-
-
cout<<"X = "<< a << "or" << c;
-
cin.ignore();
-
cin.get();
-
}
The answers i get arnt even close to the actual answers...
Please tell me what is wrong.. PLEASE PLEASE PLEASE
-------------------------------------------------------------------
This should help in understanding what i am trying to do.....
This program is supposed to solve equations like (3x^2 * -7x + 2)
so.. Using the general formula to solve this equation we take the coeff of x^2 to be "x", coeff of x to be "y" and coeff of number without unknown x to be "z".
Therefore x = 3
y = -7
z = 2
The equation to find x = ((-y) + sqrt((y^2) - (4*x*z))) / 2*x)
so... resulting to.. x = (7 + (sqrt (49 - 24)) / 6
and.. x = (7 + 5)/6
x = 2 //
As you can see.. in my code.. double b should = 25...
Any questions please ask.. i need help to solve this program.. I just really want to finish this program so please help