Ask the user to enter the coefficients a, b and c. Have your program then solve the two (or possibly one) solution(s) for X. Be careful to make sure there is a solution by confirming that the square root is not executed on a negative number which is considered to be imaginary.
Be sure to #include<cmath> and call the pow() and sqrt() functions when making your math calculations. Also note, the coefficients a b and c are to be declared as a double, as well as your two solutions for X.
this is what i did so far:
Be sure to #include<cmath> and call the pow() and sqrt() functions when making your math calculations. Also note, the coefficients a b and c are to be declared as a double, as well as your two solutions for X.
this is what i did so far:
Code:
#include <cmath> #include <iostream> using namespace std; int main () { int a; int b; int c; int x; double posx, negx; //declare positive x and negative y cout<<"Enter the value of a: "; cin>>a; cout<<"Enter the value of b: "; cin>>b; cout<<"Enter the value of c: "; cin>>c; int check; check=(b*b)-(4*a*c); if (check>0) { posx=(-b+sqrt(check))/2*a; negx=(-b-sqrt(check))/2*a; system ("pause"); return 0; } }
Comment