odinzu

10-12-2007, 05:50 AM

I have been working on this simple program for hours now and still can't figure out my problem. Could someone please lend me some help? Thanks in advance.

Instructions:

Write a complete C++ program which will prompt the user for the three coefficients of a quadratic polynomial, and will then compute and display the two zeros of that polynomial. Use the quadratic formula.

#include <iostream.h>

#include <math.h> //Find the 2 zeros using the quadratic formula.

void main (void)

{

float a = 0.0;

float b = 0.0;

float c = 0.0;

float quadraticFormula;

float quadraticFormula2;

system("cls");

cout << "Enter 1st Coefficient: ";

cin >> a;

cout << "Enter 2nd Coefficient: ";

cin >> b;

cout << "Enter 3rd Coefficient: ";

cin >> c;

if (a != 0 & b*b-4*a*c > 0)

{

quadraticFormula = -b + sqrt(b*b-4*a*c) / (2* a); //Calculates the + of the zero

quadraticFormula2 = -b - sqrt(b*b-4*a*c) / (2 * a); //Calculates the - of the zero

cout << "First Zero (+): " << quadraticFormula << endl;

cout << "Second Zero (-): " << quadraticFormula2 << endl;

}

else

{

system("PAUSE");

cout << endl;

cout << "Error! Press Any Key to Terminate...";

}//end if

return;

} //end main

Instructions:

Write a complete C++ program which will prompt the user for the three coefficients of a quadratic polynomial, and will then compute and display the two zeros of that polynomial. Use the quadratic formula.

#include <iostream.h>

#include <math.h> //Find the 2 zeros using the quadratic formula.

void main (void)

{

float a = 0.0;

float b = 0.0;

float c = 0.0;

float quadraticFormula;

float quadraticFormula2;

system("cls");

cout << "Enter 1st Coefficient: ";

cin >> a;

cout << "Enter 2nd Coefficient: ";

cin >> b;

cout << "Enter 3rd Coefficient: ";

cin >> c;

if (a != 0 & b*b-4*a*c > 0)

{

quadraticFormula = -b + sqrt(b*b-4*a*c) / (2* a); //Calculates the + of the zero

quadraticFormula2 = -b - sqrt(b*b-4*a*c) / (2 * a); //Calculates the - of the zero

cout << "First Zero (+): " << quadraticFormula << endl;

cout << "Second Zero (-): " << quadraticFormula2 << endl;

}

else

{

system("PAUSE");

cout << endl;

cout << "Error! Press Any Key to Terminate...";

}//end if

return;

} //end main