Jump to content
  • Advertisement
Sign in to follow this  
LordofMuffins

What the hell is wrong with my compiler?

This topic is 5042 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
Well, I don't know C++, but shouldn't you have
 return 0;
at the end of the function?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!