I've posted where the problem in my code is; really don't know what the problem is with it. Sorry if my code is a little confusing, I made it like this first so I can see if there are any problems with it before I compress it.
//Quadratic Formula
//First build 1/31/09
#include <iostream>
#include <string>
#include <math.h>
usingnamespace std;
int main()
{
//making variables up in here
string sAnswer = "null";
longdouble a = 0;
longdouble b = 0;
longdouble c = 0;
longdouble num1 = 0;
longdouble num2 = 0;
longdouble num3 = 0;
longdouble num4 = 0;
labelA: //label for my goto because im too lazy for loops
cout << "I can do the quadratic formula!" << endl;
cout << "I just need you to input the variables." << endl;
cout << "But first I want you to tell me if you want output" << endl;
cout << "at each calculation so you can write it down and call it yours." << endl;
cout << "Please type in a 'y' or a 'n' to indicate if I should tell you or not." << endl;
cin >> sAnswer;
cout << sAnswer << endl; //this line is for testing purposes
cout << "I'm not going to give you the output just yet. This is an alpha build!" << endl; //delete this later
//input if statement here
cout << "Please tell me the value of a." << endl;
cin >> a;
cout << "Please tell me the value of b." << endl;
cin >> b;
cout << "Please tell me the value of c." << endl;
cin >> c;
cout << "Alrighty I'm working on it now, buddy." << endl;
//the output for each calculation is to see where the problem lays in the program
//the error is occuring at the square root calculation
num1 = b * b;
cout << "B squared is: " << num1 << endl;
num2 = a * c * -4;
cout << "-4ac is: " << num2 << endl;
num3 = num1 + num2;
cout << "b squared plus -4ac is: " << num3 << endl;
num1 = sqrt(num3);
cout << "Square root of b squared plus -4ac" << num1 << endl;
num2 = b * -1;
num4 = num1;
num3 = num2 + num1;
num1 = a * 2;
num3 = num3/num1;
cout << "First result (addition): " << num3 << endl;
num3 = num2 - num4;
num4 = a * 2;
num3 = num3/num4;
cout << "Second result (subtraction): " << num3 << endl;
cout << "Go again? y/n?" << endl;
cin >> sAnswer;
cout << "Haha just kidding alpha build" << endl;
cout << "End of test" << endl;
system("PAUSE");
return 0;
}
As you can see I'm going to add a goto and the checks for it but thats after I get the math working right. Thanks for the help!
I had the steps expanded so I can output the result of each calculation, I was going to add an If statement at the beginning that would get rid of that option and then I would have something similar to your equation in the place of my expanded steps if the user didn't want to see the result at each calculation.
It's generally a good idea to assign them at creation anyway, just to make sure they have a value. Also, what helios said is basically right, if num3 < 0 then you are no real roots and that will cause some problems.