Why is program not compiling? [closed]

Taking that and compiling it gives me the simple error:

fatal error: iostream.h: No such file or directory

This is self-explanatory. The reason is that <iostream> doesn’t have an extension, or a .h equivalent. Change the line to:

#include <iostream>

Proof that it compiles (not including the following points, but removing things irrelevant to ideone): http://ideone.com/WIDjR

Aside from that:

  • You don’t need windows.h. system is part of cstdlib.

  • using namespace std; often does more bad than good. It’s recommended to stick to std::cout etc. Inside main isn’t the worst place it could be, but nonetheless, not a great habit to get into.

  • if( number >= 2 && number <= 2 ) is a logic error, both in writing and execution. The simpler form would be if (number == 2), but the correct form, based on your output, would be if (number != 2), lest every number other than 2 is the right guess.

  • system ("PAUSE") is bad. You don’t know if pause.exe will do that, or if it will even exist. Someone could have a pause.exe that formats their hard drive, and you’d be to blame for executing it. Use a form of cin.get(), or, if your compiler implements it to clear the input buffer, cin.sync(); cin.get(); for consistent behaviour. Beware that cin.sync()‘s behaviour is not guaranteed.

  • Your program should be returning 0 from normal exit. Anything else is taken to mean an error occurred. return 0; in main is implicit if you don’t specify a return value.

Leave a Comment