### Why doesnt my quadratic formula program work properly?

I am trying to create a program that calculates the quadratic formula just for practice and fun but it has been years since i have actually used it in math so im not sure if its my math that is wrong or my programming but can someone please help?
code:

#include <iostream>
#include <math.h>
using namespace std;

int main()
{

cout << "Enter in A's value: ";
double a;
cin >> a;
cout << "Enter in B's value: ";
double b;
cin >> b;
cout << "Enter in C's value: ";
double c;
cin >> c;
cout << "X is equal to: ";
double x;
x = ((-b)+ sqrt((b*b)-4*(a*c)))/(2*a);
//x = ((-b)- sqrt((b*b)-4*(a*c)))/(2*a);
cout << x;
cout << endl;
cout << "Enter any number to terminate the program";
cin >> a;
}

What's The problem?
it doesnt calculate the answer properly, at least i dont think so, i tested it with an example from google and it worked but then i got my brother in highschool who could use this program frequently to try it and it calculated the answer wrong, at least i think it did...
To solve a problem, first the problem must be identified. If you don't know whether or not there's a problem, the first step would be finding out if there actually is a problem.

If there is a problem, the next step is reproducing it.

So... try a bunch of different values out. If you get incorrect output... then tell us the following:

1) What input you gave it (values for a, b, and c)
2) What output the program gave you
3) What output is actually correct

If you try a bunch of values out and do not get incorrect output... then you have no reason to think that there's anything wrong with the program.

EDIT:
If your brother is telling you he got incorrect output. Then get the above information from him.
Last edited on
*Ignore this I am reminding myself that when I get home from work I should check this out and give you some code that I have to help you.*

EDIT: okay... here is some code (its in C, but if you can convert it into C++ that would be nice!)

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455`` ``````/* quad.c * ---------- * Quadratic Equation Problem Phase #4. */ #include //include #include "genlib.h" #include "simpio.h" #include "math.h" main() { float answer1,answer2,a,b,c,bsq,fac,ta,nob,lin; //assign variables printf ("Quadratic Equation Problem Phase #4.\n"); //Get Numbers printf ("Enter \"a\" value. "); a=GetInteger(); printf ("Enter \"b\" value. "); b=GetInteger(); printf ("Enter \"c\" value. "); c=GetInteger(); bsq=b*b; //initialization fac=4*a*c; ta=2*a; nob=-1*b; lin=-1*(c/b); if (bsq

if you need me to explain anything, just ask
Last edited on
Topic archived. No new replies allowed.