Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello Sir. I am having problems running a program to calculate Quadratric Equati

ID: 3636840 • Letter: H

Question

Hello Sir.

I am having problems running a program to calculate Quadratric Equation. Here is my own source code. Please i need help to help me modify or find the mistakes.

=======================================================================

// Calculating A Quadratic Equation
#include <iostream>
#include <math.h>
using namespace std;

int main ()
{
//Declaring Variables
int a, b, c;
int d = ( b * b ) - (4 * a * c);
double x;
double xx;

//Read the Values and Input Values Of Variables
cout <<"Enter Value Of A :";
cin>>a;
cout <<"Enter Value Of B: ";
cin>>b;
cout <<"Enter Value Of C: ";
cin>>c;

//Solving The Equation
if ( d == 0 ) {
x = -b/(2*a);
xx = x;
}
else if (d > 0) {
x = -b + sqrt (d)/(2*a);
xx = b + sqrt (d)/ (2*a);
}
else if ( d < 0) {
cout << " imaginary roots ";
}
// Print result
cout<<" The Value Of X:"<<x<<endl;
cout<<" The Value Of X_2:"<<xx<<endl;

system ("pause");
return 0;
}

Explanation / Answer

please rate - thanks

 

you just have to move the definition of d

can't use a,b and c if they have no values in them yet, plus your numerator formula is incorrect, and when d=0


// Calculating A Quadratic Equation
#include <iostream>
#include <math.h>
using namespace std;

int main ()
{
//Declaring Variables
int a, b, c;

double x;
double xx;

//Read the Values and Input Values Of Variables
cout <<"Enter Value Of A :";
cin>>a;
cout <<"Enter Value Of B: ";
cin>>b;
cout <<"Enter Value Of C: ";
cin>>c;
int d = ( b * b ) - (4 * a * c);
//Solving The Equation
if ( d == 0 ) {
cout<<"undefined ";
}
else if (d > 0) {
x = (-b + sqrt (d))/(2*a);
xx = (-b - sqrt (d))/ (2*a);
// Print result
cout<<" The Value Of X:"<<x<<endl;
cout<<" The Value Of X_2:"<<xx<<endl;
}
else if ( d < 0) {
cout << " imaginary roots ";
}


system ("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote