VB icon

A quadratic equation solver

Email
Submitted on: 1/7/2015 11:38:00 AM
By: Mauricio Rossi (from psc cd)  
Level: Intermediate
User Rating: By 6 Users
Compatibility: C++ (general), Microsoft Visual C++, Borland C++
Views: 1036
 
     This program solves quadratic equations for you. All you have to do is enter the value of a, b, and c. I wanted to check my homework for my math class, so i made this program mainly overnight.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: A quadratic equation solver
// Description:This program solves quadratic equations for you. All you have to do is enter the value of a, b, and c. I wanted to check my homework for my math class, so i made this program mainly overnight.
// By: Mauricio Rossi (from psc cd)
//
// Inputs:A,B,C
//**************************************

#include <cmath>
#include <iostream>
char e;
using namespace std;
void calculate();
void ask();
int main() {
cout << "\t Quadratic Equation Solver\n\t\t by Mauricio Rossi\n\n";
cout << "This program will solve quadratic equations for you.\n";
cout << "Just enter the values of A,B, and C of a qudratic equation.\n";
calculate(); 
return 0;
}
void ask(){
cout << "Would you like to solve another equation Y/N?";
cin >> e;
if (e == 'y' || e == 'Y'){
calculate();
}
if(e == 'n' || e == 'N'){ }
else {
cout << "Invalid command\n";
system("PAUSE");
}
}
void calculate(){
double a,b,c,a1,a2,a3,nb,sb,divider,result1,result2,div,div2;
cout << "Enter value of A\t";
cin >> a;
cout << "Enter value of B\t";
cin >> b;
cout << "Enter value of C\t";
cin >> c;
nb = -b;
sb = pow(b, 2);
a1 = -4 * a * c;
a2 = sb + a1;
a3 = sqrt(a2);
result1 = nb - a3;
result2 = nb + a3;
divider = 2 * a;
div = result1 / divider;
div2 = result2 / divider;
cout << "The answer is:\t(" << div << "," << div2 << ")" << "\n"; 
ask();
}


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 Intermediate 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.