calculating a simple math algorithm

Hi every one, I have to design a simple algorithm and it is to calculate roots of a quadratic equation, it has to read data, post errors if they are not suitable and also it has to use header files to manage errors, anyone here I can find?
In fact I have 2 problems, I need to use hear files but my visual studio does not work, my other problem is that I wrote the code without headers but it has a lot of errors.
The code is as follows:
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849`` ``````#include #include #include #include #include using namespace std; #include #include "stdio.h" //try to execute the following code //i hope it will work properly #include int main() { int a,b,c,discriminant; float r1,r2,d,x1,x2; cout<<"enter the values of a,b,c"; cin>>a>>b>>c; if(a==0) { d=-c/b; cout<<"matherror, this is not a quadratic equation and root is equal to:"<0) { x1=(-1*b+sqrt(discriminant))/(2*a); x2=(-1*b-sqrt(discriminant))/(2*a); } else if(discriminant==0) { r1=r2=(-1*b)/(2*a); } else { cout<<"matherror, this equation does not have real answer"; } cout<<"x1="<

When I run it I see the following errors:
c:\program files\microsoft visual studio 10.0\vc\include\iostream(25): error C2146: syntax error : missing ';' before identifier 'cin'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

1>c:\program files\microsoft visual studio 10.0\vc\include\iostream(27): error C2146: syntax error : missing ';' before identifier 'cerr'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
pe specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream(32): error C2146: syntax error : missing ';' before identifier 'wcerr'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream(32): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream(33):
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\cmath(8): error C2297: '<<' : illegal, right operand has type 'const char [4]'
1>c:\program files\microsoft visual studio 10.0\vc\include\cmath(8): warning C4552: '<<' : operator has no effect; expected operator with side-effect
1>c:\program files\microsoft visual studio 10.0\vc\include\iosfwd(635): error C2378: 'std::istream' : redefinition; symbol cannot be overloaded with a typedef
1> c:\program files\microsoft visual studio 10.0\vc\include\iostream(26) : see declaration of 'std::ostream'
1>c:\program files\microsoft visual studio 10.0\vc\include\iosfwd(655): error C2378: 'std::wistream' : redefinition; symbol cannot be overloaded with a typedef
1> c:\program files\microsoft visual studio 10.0\vc\include\iostream(30) : see declaration of 'std::wistream'
1>c:\program files\microsoft visual studio 10.0\vc\include\iosfwd(656): error C2378: 'std::wostream' : redefinition; symbol cannot be overloaded with a typedef
1> c:\program files\microsoft visual studio 10.0\vc\include\iostream(31) : see declaration of 'std::wostream'
1>c:\program files\microsoft visual studio 10.0\vc\include\cmath(6): error C2084: function 'int main(void)' already has a body
1> c:\program files\microsoft visual studio 10.0\vc\include\cmath(5) : see previous definition of 'main'
1>c:\program files\microsoft visual studio 10.0\vc\include\cmath(8): error C2297: '<<' : illegal, right operand has type 'const char [4]'
1>c:\program files\microsoft visual studio 10.0\vc\include\cmath(8): warning C4552: '<<' : operator has no effect; expected operator with side-effect
1>c:\users\me\documents\visual studio 2010\projects\genethic\genethic\genethic.cpp(19): error C2297: '<<' : illegal, right operand has type 'const char [26]'
1>c:\users\me\documents\visual studio 2010\projects\genethic\genethic\genethic.cpp(24): error C2297: '<<' : illegal, right operand has type 'const char [66]'
1>c:\users\me\documents\visual studio 2010\projects\genethic\genethic\genethic.cpp(24): error C2297: '<<' : illegal, right operand has type 'float'
1>c:\users\me\documents\visual studio 2010\projects\genethic\genethic\genethic.cpp(24): warning C4552: '<<' : operator has no effect; expected operator with side-effect

I tried to delete repeatitions from errors.
I've seen something like this before. It turned out to be a bad upgrade from one version of VS to another and a fumbled "conversion" of some project format. I think the solution was to just uninstall everything relating to VS and do a fresh, clean install.
I did not upgrade it but it seems that I need to reinstall it but I think there are some ways to prevent re-installation.
Last edited on
You might want to try doing a simple "Hello World" program to see if even that compiles.

If that fails then your PATH might be wrong, or you have duplicate/and-or missing files in several INCLIDE and LIB paths that can cause problems when compiling.
I'm saying this becuase I see it has problems recognizing the 'cin' and '<< ' identifiers.

Despite these errors there are only two errors that you should fix,
line 46 you have two "<<" after the "x2" string,
and you need to include <math.h> if you want to use the sqrt function.
Last edited on
My 2 cents worth:

Why stdio.h?

Don't use goto !!
From what I remember, thats standard i/o. Isnt that a C program?

I think you have to much in your includes section. The only one i see that you need is
` #include <iostream> `

Topic archived. No new replies allowed.