I just started studying structured programming and I was trying to do a If Else then function but the compiler won't let me compile it?

#include <iostream>              
using namespace std;    

int main (void)
   {

int age; 

        cout << "Enter your age" << end1;
        cin >> age;
if(age > 21)
   {
        cout << "You can drink." << endl;

}
    else 
    {
        cout << "You can't drink." << endl; }

}

Recommended Answers

All 8 Replies

int age;

cout << "Enter your age" << end1;
cin >> age;

Ha Ha Ha Look at the second line end1;
it should be endl not end1

Don't forget the return value..

>Don't forget the return value..
0(zero) is returned by default. You don't need to return a value.
As mentioned by Bajarne Stroustrup, this is a perfectly valid shortest C++ program:

int main() {}

>Don't forget the return value..
0(zero) is returned by default. You don't need to return a value.
As mentioned by Bajarne Stroustrup, this is a perfectly valid shortest C++ program:

int main() {}

of course..How about 3..U know the best..

you can also use:

void main (instead of int main())

and if you are using int main() please return some value like "return 0;"

and its endl not end1

:)

commented: NEVER USE VOID MAIN +0

Now what should I say to charleen.
Should I get angry or should I blow my head.
charleen, NEVER USE VOID MAIN. Okay? and say it 100 times," I WILL NEVER USE VOID MAIN".
Go and search the internet about this:
This is from Bajarne Stroustup Official Homepage :http://www.research.att.com/~bs/bs_faq2.html#void-main
And this is a small article about why not to use void main:http://cppdb.blogspot.com/2009/02/should-i-use-void-main-or-int-main-or.html
And you know Salem? He is a valuable poster on this forum, look at his avatar:[img]http://www.daniweb.com/forums/customavatars/avatar57744_3.gif[/img]

>and if you are using int main() please return some value like "return 0;"
As I told you, there is no need to return 0; this is what Bajarne Stroustrup write on his page : These are the lines quoted from his page :

In C++, main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution.

Such a post shows your unexperienced and non-standard behavior towards C++

Yo..Take it ez..U dont even better than him..So..:p

Now what should I say to charleen.
Should I get angry or should I blow my head.
charleen, NEVER USE VOID MAIN. Okay? and say it 100 times," I WILL NEVER USE VOID MAIN".
Go and search the internet about this:
This is from Bajarne Stroustup Official Homepage :http://www.research.att.com/~bs/bs_faq2.html#void-main
And this is a small article about why not to use void main:http://cppdb.blogspot.com/2009/02/should-i-use-void-main-or-int-main-or.html
And you know Salem? He is a valuable poster on this forum, look at his avatar:[img]http://www.daniweb.com/forums/customavatars/avatar57744_3.gif[/img]

>and if you are using int main() please return some value like "return 0;"
As I told you, there is no need to return 0; this is what Bajarne Stroustrup write on his page : These are the lines quoted from his page :


Such a post shows your unexperienced and non-standard behavior towards C++

Thanks for correcting me and I am really sorry because this is what we are taught... "using void main"

It's basically not my mistake :(

And i am here to learn... and sorry once again....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.