VB icon

Calculates Quadratic Formula

Email
Submitted on: 1/2/2015 5:24:00 AM
By: Guy Fischman (from psc cd)  
Level: Beginner
User Rating: By 2 Users
Compatibility: C, C++ (general)
Views: 950
 
     This code applies the quadratic formula to an equation and derives the variable value given the three coefficients.
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :Calculates Quadratic Formula
//**************************************
iostream.h
math.h
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Calculates Quadratic Formula
// Description:This code applies the quadratic formula to an equation and derives the variable value given the three coefficients.
// By: Guy Fischman (from psc cd)
//
// Inputs:Three coefficients of a quadratic equation.
//
// Returns:Value of unknown variable.
//**************************************

#include <iostream.h>
#include <math.h>
void main()
{
 double A;
 double B;
 double C;
 double disc;
 cout << "Enter A: ";
 cin >> A;
 cout << "Enter B: ";
 cin >> B;
 cout << "Enter C: ";
 cin >> C;
 disc = B*B - 4*A*C;
 if (disc < 0){
 cout << "Imaginary results: " << endl;
 cout << "(" << B * (-1) << " + " << sqrt(disc * (-1)) << "i) / " << 2*A << endl;
 cout << "(" << B * (-1) << " - " << sqrt(disc * (-1)) << "i) / " << 2*A << endl;
 }
 else if (disc == 0){
 cout << "Single result: " << (-B)/(2*A) << endl;
 }
 else{
cout << "Two results: " << endl;
cout << (B * (-1) + sqrt(disc)) / (2*A) << endl;
cout << (B * (-1) - sqrt(disc)) / (2*A) << endl;
 }
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.