#include %26lt;iostream%26gt;
#include %26lt;math.h%26gt;
#include %26lt;iomanip%26gt;
using std::fixed
using std::setprescision;
using std::sqrt;
void main ()
{
int a, b, c;
double x1, x2, d;
char choice;
cout %26lt;%26lt; "Enter the dco-efficient of x square";
cin %26gt;%26gt; a;
cout %26lt;%26lt; "Enter the co-efficient of x";
cin %26gt;%26gt; b;
cout %26lt;%26lt; "Enter the constant";
cin %26gt;%26gt; c;
if ( a==0 )
cout %26lt;%26lt; "Zero divide.";
else
{
d = (b^2) - (4ac);
if (d %26gt;= 0)
{
cout %26lt;%26lt; fixed;
cout.precision (3);
x1 = (-b + sqrt (d))/(2.0 * a);
x2 = (-b - sqrt (d))/(2.0 * a);
cout %26lt;%26lt; "The two roots are"
%26lt;%26lt; x1 %26lt;%26lt; " and " %26lt;%26lt; x2;
}
else
cout %26lt;%26lt; "No real roots.";
}
cout %26lt;%26lt; "Do you want to continue ( Q : Quit)?";
C++ program HELP this is not compiling?
the carrot is not a C++ operator, this line is invalid:
d = (b^2) - (4ac);
you can't imply multiplication that way. you have to use an astrix also.
The compiler thinks it's a number when it sees a number starting a string with no spaces.
you should try
d = pow(b,2) - 4 * a * c;
Reply:It has been a while since I programmed in C++, but I will try to help. I remember how frustrating it can be to debug!
using std::fixed (needs a ;)
cout %26lt;%26lt; "Zero divide."; (don't think it needs ;)
(cause it's part of if else)
cout %26lt;%26lt; fixed; (not sure about this)
cout.precision (3); (fixed is not a defined )
(variable)
It looks like there is more to the program. Let me know if this helps or you need me to look at more of it.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment