Quadratic equation solver

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

int main()
{

float a;
float b;
float c;

cout << "welcome to the quadratic formula solver! n" ;

cout << "enter a " ;
cin >> a ;

cout << "enter b " ;
cin >> b ;

cout << "enter c " ;
cin >> c ;

float bsquare = b * b;
float twoa = 2 * a;
float fourac = 4 * a * c;
float oppositeb = -b;
float discriminant = bsquare - fourac;
float squareroot = sqrt (discriminant);
float top1 = oppositeb - squareroot;
float answer1 = top1 / twoa;
float top2 = oppositeb + squareroot;
float answer2 = top2 / twoa;

cout << "the answer to the quadratic equation is: " << answer1 << " , " << answer2 << ". n" ;
cout << "the discriminant is: " << discriminant << ". n" ;

system("PAUSE");
return 0 ;
}

0 Comments

You must be logged in to post a comment.