• 14
• 12
• 9
• 10
• 13

What the hell is wrong with my compiler?

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

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 on other sites
Well, I don't know C++, but shouldn't you have
 return 0;
at the end of the function?

Share on other sites
You're using a deprecated header. Use #include <iostream>

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.

Argh, too slow [smile]
[/edit]

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

Share on other sites
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 MushuWell, 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 on other sites
... Damn it. AP = yours truly.

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

Share on other sites
Quote:
 Original post by LordofMuffinsStill 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.