quadratic equation solver

Just finished some new code and wanted to share it because mabye some people would like it, Here it is. It solves quadratic equations and puts this (x+a)(x+b) in standard form for solving.


#include <iostream>
#include <math.h>
using namespace std;
//MASS ALOCATION!!! LOL
float x1plus;
float x2plus;
int one;
int two;
int dude;
int x;
int a;
int b;
int c;
double power;
double bob;
double dis;
double joemama;
int bottom;
double answer1;
double answer2;
int main()
{
one = 1;
two = 2;
cout << "Quadratic Equation Solver by Ryan Parker\n" << endl;
cout << "type 1 and press enter if your problem is in standard form" << endl;
cout << "type 2 if its in (x+a)(x+b) form." << endl;
cin >> dude;
if (dude == 1)
{
for (x = 0; x <= 40; x++)
{
cout << "ax^2+bx+c" << endl;
cout << "imput the 'a' variable: " << endl;
cin >> a;
cout << "imput the 'b' variable: " << endl;
cin >> b;
cout << "imput the 'c' variable: " << endl;
cin >> c;
bottom = 2*a;
power = pow (b,2);
bob = 4*a*c;
dis = power - bob;
cout << "This is the Discriminenet: " << dis << endl;
if (dis < 0)
{
cout << "discriminent is less than zero, Answer is imaginary!" << endl;
cout <<"\n" << endl;
cout <<"\n" << endl;
}
else
{
joemama = sqrt(dis);
answer1 = (-b+joemama);
answer2 = (-b-joemama);
cout << "x=" << answer1 / bottom << endl;
cout << "x=" << answer2 / bottom << endl;
cout << "\n" << endl;
cout << "\n" << endl;
}
}
}
else if (dude == 2)
{
for (x = 0; x <= 40; x++)
{
cout << "imput the number after x1" << endl;
cin >> x1plus;
cout << "imput the number after x2" << endl;
cin >> x2plus;
cout << "in standard form: x^2+" << x1plus+x2plus << "x+" << x1plus*x2plus << endl;
}
}
else
{
cout << "come on, only 1 or 2";
}
return 0;
}
Last edited on
Thanks for sharing, you may want to put it in the source code sub category of the articles http://www.cplusplus.com/articles/sourcecode/ ...
But please use code tags, thank you :)
Topic archived. No new replies allowed.