I am writing this Quadratic Equation Solver for school. As I write my output section the cout and cin get red-lined by Microsoft visual 2010 Express. The final getch and return statements are also red-lined. I do not know what I have done wrong to cause them to error out. If you could help me I would be very appreciated. ~Beverly
Just some quick program specifics: Must contain two string constants (Quadratic Function, and a border), also to use at least 2 value returning functions for all calculations.
Program Purpuse: To solve a quadratic equation using floating point
solutions and discriminents that are not negative.
*/
#include <iostream> //Input Output (cout and cin)
#include <cmath> //Computes common math (sqrt and pow)
#include <string> //Programmer defined data type
#include <conio.h> //Console Input Output
usingnamespace std;
//Below are functions to compute the neg. and pos. results from the quadratic formula
double FindPos(double a, double b, double c)
//Preconditions: The value of the plus quadratic formula is known.
//Postconditions: The formula is calculated and returned.
{
double PosX;
PosX = ((-b) + sqrt((pow(b,2)) - (4*a*c))) / (2*a);
return PosX;
}
double FindNeg(double a, double b, double c)
//Preconditions: The value of the minus quadratic formula is known.
//Postconditions:The formula is calculated and returned
{
double NegX;
NegX = ((-b) - sqrt((pow(b,2)) - (4*a*c))) / (2*a);
return NegX;
}
//Below are string constants for name and border.
const string QUADFORM = "Quadratic Formula";
const string BORDER = ("%%%%%%%%%%%%%%%%%")
int main()
{
//Declaration Section
double a;
double b;
double c;
double PosX;
double NegX;
//Input Section
cout << "Enter the value for a: " << endl;
cin >> a;
cout << "Enter the value for b: " << endl;
cin >> b;
cout << "Enter the value for c: " << endl;
cin >> c;
//Processing Section
PosX = FindPos(a,b,c);
NegX = FindNeg(a,b,c);
//Output Section
cout << BORDER << BORDER << BORDER << BORDER << BORDER << endl;
cout << "" << endl;
cout << QUADFORM << endl;
cout << "" << endl;
cout << "a= " << a << "b= " << b << "c= " << c << endl;
cout << "When adding the discriminant x= " << PosX << endl;
cout << "When subtracting discriminant x= " << NegX << endl;
cout << BORDER << BORDER << BORDER << BORDER << BORDER << endl;
getch();
return 0;
}