Hello --- relatively new C++ programmer here (have experience with Visual Basic but not extensively). I am trying to get the following code to compile using Borland's command line compiler and it just will not... I got the code from John Smiley's "Learning to Program C++" - this is not the exact code he uses in the book but any change is so minor I can't see why this wont't run. I have tried multiple variations of the code and none of them work ---- the compiler does it's thing, makes my .exe file. Then I launch the .exe file and it does nothing except give me a new command prompt. I am rewriting my code from memory because I am on a work computer and the code I on a different computer --- but it is so simple I can pretty much remember it verbatim. Anyways, here's the code:
#include <iostream>
using namespace std;
void DisplayMessage();
#include <iostream>
usingnamespace std;
void DisplayMessage();
main(){
DisplayMessage(); // void should not be used here
return 0;
}
void DisplayMessage(){
cout<<"I love C++!!!";
}
Worked like a charm --- thanks Stewbond. Funny, I would never have thought that an extra type on void would have mattered.
By the way, I'm using the Borland Compiler.... I know VS Express is free --- but I kind of like the coolness of using a non-microsoft product. Do you know of any drawbacks? Cause if there weren't any errors in my code, I was suspecting the compiler.... but I guess the compiler works just fine?
By the way, I'm using the Borland Compiler.... I know VS Express is free --- but I kind of like the coolness of using a non-microsoft product. Do you know of any drawbacks? Cause if there weren't any errors in my code, I was suspecting the compiler.... but I guess the compiler works just fine?
One issue is that you need to put int main(). main must always return an int, you are not allowed to leave it off like some compilers will erroneously allow you to.
As for your actual code, the reason why it doesn't work is that your line 6 was doing exactly the same thing as your line 3, prototyping a function. It wasn't calling a function.
Most of the time, the compiler is not to blame. However, the Borland compiler is quite old, and isn't particularly recommended. The product line is now owned by Embarcadero http://www.embarcadero.com/
Unfortunately, I don't think they have any free compiler nowadays.