So I had this nifty program on my calculator that I wrote that sloves quadratic equations for me. I decided it would be good practice to try and write it in C++. I've actually had 4 different versions, each one (atleast in my opinon) getting better than the last. When I went to compile this one, for some reason when Dev C++ gets to the opening brace for the whatnext function it says there is a parse error. I bet I'm doing something stupidly small. Could I get some help? Any other suggestions on makeing the program more sleek and efficient would also be appreciated.
Source code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
// declare prototypes
void whatnext (void);
void solver (void);
//global varible declarations
double a;
double b;
double c;
double y;
double e;
double d;
int main (int nNumberofArgs, char* pszArgs[])
{
// Start of main program loop
for (;; )
{
int chose;
cout << "Type 1 to solve for an equation and 2 to exit:";
cin >> chose;
//Exit or solve
//solve
if (chose == 1)
{
// ask for variables
cout << "What does A equal?:";
cin >> a;
cout << "What does B equal?:";
cin >> b;
cout << "What does C equal?:";
cin >> c;
cout << "What does Y equal?:";
cin >> y;
//call to decsion function
whatnext();
}
//exit
else
{
cout << "Thank you for using Kurt's Quadsolver" << endl;
//pause and let them read my beautiful statement
system("PAUSE");
return 0;
}
}
void whatnext (void)
{
//preliminary computations
c -= y;
d = -(b / (2 * a));
e = (b * b) - (4 * a * c);
//decide what to do
//if there is no solution
if (e < 0)
{
cout << "No Solution. \nSorry.\n";
system("PAUSE");
//return to caller
}
//call the solving function
else
{
solver();
}
}
//solver function
void solver(void)
{
//for one solution
if (e == 0)
{
//declare helper f variable
double f;
e = sqrt ( e ) / (2 * a );
f = d - e;
//display answers and let them see it
cout << "Solution 1: \n";
cout << f;
cout << "\nYour welcome. \n";
system("PAUSE");
//return to calling function
}
//two solutions
else
{
e = sqrt( e ) / (2 * a);
//declare helper f and g variables
double f;
double g;
f = d - e;
g = d + e;
//display solutions
cout << "Solution 1: \n";
cout << f;
cout << "\nSolution 2: \n";
cout << g;
cout << "\nYour welcome. \n";
system ("PAUSE");
//return to calling function
}
}
<< moderator edit: added code tags: [code][/code] >>