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;
}
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.