
Untitled
By: a guest on
Apr 25th, 2012 | syntax:
C++ | size: 1.13 KB | hits: 29 | expires: Never
//Homework 7, question 3
#include <iostream>
#include <math.h>
using namespace std;
void calculateQuadratic(double a, double b, double c, double &x1, double &x2)
{
double value;
value = b * b - 4. * a * c;
if (value >= 0)
{
x1 = (b + value) / 2. * a;
x2 = (-b - value) / 2. * a;
}
else if (value < 0)
{
x1 = (b + value) / 2. * a;
x2 = (-b - value) / 2. * a;
} //for the imaginary part
}
int main(int argc, char **argv)
{
double a, b, c; //input
double x1, x2; // output
int i;
if (argc == 1)
{
cout << "enter a: ";
cin >> a;
cout << endl;
cout << "enter b: ";
cin >> b;
cout << endl;
cout << "enter c: ";
cin >> c;
}
if (argc == 4)
{
calculateQuadratic(atof(argv[1]), atof(argv[2]),
atof(argv[3]), x1, x2);
}
if (argc == 5)
{
}
system("pause");
return 0;
}