What the hell is wrong with my compiler?

Started by
21 comments, last by Evil Steve 19 years, 6 months ago
I'm running Dev c++ beta and it won't compile the following:

//compute n!
#include <iostream.h>

int main() {
      int n;      //The number the user types in.
      int Result = 1;
      int i;      //Loop variable.
      
      //Get the value.
      cout << "What is the number?" endl ;
      cin >> n;
      
      //Now loop through. Each time through the loop
      //multiply the result by i. This will give
      //1*2*3...n because i starts at 1 and increases
      //until it is n.
      for (i=1; i<=n; i++) {
             Result *= i;
      }
      
      //Print the result.
      cout << "n! is " << Result << endl;
}              
[Edit: Use the [source] tag to improve legibility. See the Site FAQ for more information. - Oluseyi.] WTF? These are the errors I'm getting: 2 C:\Dev-Cpp\include\c++\3.3.1\backward\iostream.h:31, from main.cpp In file included from C:/Dev-Cpp/include/c++/3.3.1/backward/iostream.h:31, from main.cpp 2 C:\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated. C:\Dev-Cpp\main.cpp In function `int main()': Holy **** there are a ton of errors... I don't wanna list the rest...help? [Edited by - Oluseyi on October 2, 2004 12:16:48 PM]
Advertisement
Well, I don't know C++, but shouldn't you have
 return 0;
at the end of the function?
You're using a deprecated header. Use #include <iostream>
Ra
You can get rid of the compiler warnings by replacing
#include <iostream.h>

with
#include <iostream>using namespace std;


iostream.h should not be used anymore.

[edit]
Argh, too slow [smile]
[/edit]
It still isn't working. It's a console application. What the hell is wrong with this? Where should I put return 0? And why don't I need the .h?
It is extremely irritating when people blame programming errors on compilers. As Ra pointed out, you should use <iostream> instead of <iostream.h> (note that the imported symbols will now reside in the std namespace rather than the global one); if you want help with the other errors, you will have to provide more details.

Quote:Original post by Mushu
Well, I don't know C++, but shouldn't you have
return 0; at the end of the function?

This is optional. Every function that returns a non-void value shall include an explicit return statement, but main is an exception—in the absence of an explicit return statement, it returns 0, which generally signifies successful completion.
... Damn it. AP = yours truly.
Still not working. I changed int main to void main, I thought that would work, but it doesn't...apparently that's the only problem now.
Quote:Original post by LordofMuffins
Still not working. I changed int main to void main, I thought that would work, but it doesn't...apparently that's the only problem now.

void main is not legal; main shall always return an int.
At least he still should try to put return 0; as the last statement of main() to see what happens. I find it more safe never to assume that compilers recognize fine nuances of a language like this particular example. Nevertheless I believe DevCPP supports this; in fact it does not warn if I forget to return a value in any normal function as fall, and it is an constant source of crashes (another reason not to omit returns).

EDIT: What is the error message you got this time?

This topic is closed to new replies.

Advertisement