J
James Phillips
can anyone tell me how to correct the error in this code snippet: ?
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <float.h>
using namespace std;
void end();
void begin();
void compute_x(float a, float b, float c);
void compute_y(float a, float b, float c);
void error(int num);
int main(int argc, char *argv[])
{
system("CLS");
begin();
return 0;
}
void begin(void)
{
float a, b, c, x, y;
cout << "The Quadratic Formula solver.\n\n";
cout << "Enter a value for A: ";
cin >> a;
cout << "Enter a value for B: ";
cin >> b;
cout << "Enter a value for C: ";
cin >> c;
if(_isnan(x) || _isnan(y)){
cout << "The answer is unreal!\n\n";
end();
} else {
cout << "The answer is: X= " << compute_x(a, b, c) << " and
Y= " << compute_y(a, b, c) << ".\n\n";
end();
}
}
void compute_x(float a, float b, float c)
{
float x;
x = (pow(b, 2) - 4 * a * c);
x = ((-b) + sqrt(x)) / (2/a);
return x;
}
void compute_y(float a, float b, float c)
{
float y;
y = (pow(b, 2) - 4 * a * c);
y = ((-b) - sqrt(y)) / (2/a);
return y;
}
void end(void)
{
int num;
cout << "Options\n\n";
cout << "1. Do another equation.\n";
cout << "2. Return to Mathematics Wizard Main Menu\n";
cout << "3. Exit\n";
cout << "\nEnter the number of your choice: ";
cin >> num;
if(num == 1) { begin(); }
else if(num == 2) { cout << "Function not yet implemented!"; }
else if(num == 3) { exit(0); }
else { error(num); }
}
void error(int num)
{
cout << "You idiot! " << num << " isn't a valid response!\n\n";
end();
}
Thanks
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <float.h>
using namespace std;
void end();
void begin();
void compute_x(float a, float b, float c);
void compute_y(float a, float b, float c);
void error(int num);
int main(int argc, char *argv[])
{
system("CLS");
begin();
return 0;
}
void begin(void)
{
float a, b, c, x, y;
cout << "The Quadratic Formula solver.\n\n";
cout << "Enter a value for A: ";
cin >> a;
cout << "Enter a value for B: ";
cin >> b;
cout << "Enter a value for C: ";
cin >> c;
if(_isnan(x) || _isnan(y)){
cout << "The answer is unreal!\n\n";
end();
} else {
cout << "The answer is: X= " << compute_x(a, b, c) << " and
Y= " << compute_y(a, b, c) << ".\n\n";
end();
}
}
void compute_x(float a, float b, float c)
{
float x;
x = (pow(b, 2) - 4 * a * c);
x = ((-b) + sqrt(x)) / (2/a);
return x;
}
void compute_y(float a, float b, float c)
{
float y;
y = (pow(b, 2) - 4 * a * c);
y = ((-b) - sqrt(y)) / (2/a);
return y;
}
void end(void)
{
int num;
cout << "Options\n\n";
cout << "1. Do another equation.\n";
cout << "2. Return to Mathematics Wizard Main Menu\n";
cout << "3. Exit\n";
cout << "\nEnter the number of your choice: ";
cin >> num;
if(num == 1) { begin(); }
else if(num == 2) { cout << "Function not yet implemented!"; }
else if(num == 3) { exit(0); }
else { error(num); }
}
void error(int num)
{
cout << "You idiot! " << num << " isn't a valid response!\n\n";
end();
}
Thanks