Help! I'm trying to solve a quadratic equation
I keep getting the error :
term does not evaluate to a function taking 1 arguments
Heres the program. I highlighted the problem line
// Macros 3 - finding the root of a quadratic equation
// ax^2 + bx + c --> positive root = (-b+ (sqrt(b^2 - 4*a*c))) / 2a
// This program still has 2 flaws: it only solves one of the two roots of a quadratic equation
// and if the c part of the equation is 0 it will not solve the input quadratic
#include <iostream>
using namespace std;
double Abs(double Nbr);
double SquareRoot(double Nbr);
double Subfunction(double a, double b, double c);
inline double ROOT(double a, double b, double Nmbr) {return ((-b + Nmbr)/(2*a));}
// solves the (b^2 - 4*a*c) part of the equation to be put into square root solving functions
double Subfunction(double a, double b, double c)
{
double SubfunctionResult;
SubfunctionResult = ((b*b)-4(a)(c));
return SubfunctionResult;
}
// This is part of a function for solving a square root.
// It works with SquareRoot()
double Abs(double Nbr)
{
if( Nbr >= 0 )
return Nbr;
else
return -Nbr;
}
// This is part of a function for solving a square root.
// It works with Abs()
double SquareRoot(double Nbr)
{
double Number = Nbr / 2;
const double Tolerance = 1.0e-7;
do Number = (Number + Nbr / Number) / 2;
while( Abs(Number * Number - Nbr) > Tolerance);
return Number;
}
int main()
{
double x=1;
double y=1;
double z=1;
double i;
for (;;)
{
cout << "Enter the three parts to a quadratic equation in the form a^2 + b + c (0 to quit): ";
cin >> x;
cin >> y;
cin >> z;
if (x || y || z==0)
break;
cout << "You entered: " << x;
cout << "You entered: " << y;
cout << "You entered: " << z << endl;
double SubfunctionResult1 = Subfunction(x,y,z);
double Number = SubfunctionResult1;
double Number1 = SquareRoot(Number);
cout << "ROOT(" << x << " " << y << " " << z << " ): ";
cout << ROOT(x,y,Number1) << "." << endl;
}
return 0;
}