Hey guys I am a newbie with C++, and I am trying to write a program that calculates the roots for the quadratic equation, with one restriction. The value for a must be bigger than 0. I wrote the program compile it and it is working, but when I go the .exe file and open it, the program starts it allows me to enter the values for a,b, and c and then when it should display the discriminant the console windows just exits, no error messages nothing. I tried changing “int main ()” to “void main ()” without effect. When I go to debug and start debugging at the debug window a message is displayed :
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
The thread 0xC10 has exited with code 0 (0x0).
The program 'C:\Documents and Settings\HQZ\My Documents\Documents\In Progress\CSC 2311\Debug\Project 1.exe' has exited with code 0 (0x0).
And here is the actual source code:
Code:
#include <iostream.h>
#include <math.h>
#include <iomanip.h>
int main()
{
double a, b, c, discr, x_1, x_2, discr_1;
cout<<endl;
cout<<"ax^2 + bx + c"<<endl<<endl;
cout<<"Please enter the values for a, b, and c using the format above."<<endl<<endl;
cout<<"Please enter value for a: ";
cin>> a;
while (a <= 0)
{
cout<<endl<<"The value for a must be larger than 0"<<endl;
cout<<endl<<"Please enter a new value for a: ";
cin>> a;
}
cout<<"Please enter value for b: ";
cin>> b;
cout<<"Please enter value for c: ";
cin>> c;
discr = b*b - 4*a*c;
cout<<endl<<"The discriminant for the equation is: "<<discr<<endl<<endl;
if (discr <=0)
{
cout<<"The value for the expression is not in the real numbers!"<<endl<<endl;
}
else
discr_1 = sqrt(discr);
x_1 = -b+discr_1;
x_2 = -b-discr_1;
cout<<"The two roots of the quadratic equation are:"<<endl<<endl<<endl;
cout<<setw(30)<<x_1<<endl;
cout<<setw(30)<<x_2<<endl<<endl<<endl;
return 0;
}
Thanks