Could anybody please help me with my Intro to C++ programing homework? - by lizardfuel55
Queue on 18/9/2010 at 18:33
Quote Posted by Kolya
And don't follow Queue's example!
Generally good advice.
Quote Posted by demagogue
Code:
int main()
{
using namespace std;
cout << "I get an A on this, you get a blowjob. Think about it." << endl;
}
Fixed.
Thief13x on 18/9/2010 at 18:58
Quote Posted by Sulphur
whoah, back in the day (when programming for Win 95 apps was as painful as having teeth pulled out) when I learned C++, I used to include iostream.h and declare main() as void, and wasn't bothered about adding an endl to my cout's since a \n was easier.
Things sure have changed in 15 years.
Well, it could just be style. I work with C that was written back in 1996 pretty much daily for work and have never seen
endl used either there or in our newer code. Returning an
int from any function including main is used in all our code whether it's Java, C++, scripts, or the old C stuff for error checking. In most textbook examples they do seem to use void though:erg:.
Queue on 18/9/2010 at 19:10
...at least none that'd give me the time of day.:mad:
Thief13x on 18/9/2010 at 19:14
...oh come on, you don't need that long
Ulukai on 18/9/2010 at 19:27
There's nothing weird, new or stylistic about main returning an int, it's often done to supply an exit code so that you know if the program screwed up or not in the absence of any other kind of error logging.
Al_B on 18/9/2010 at 19:43
Just to be a complete pedant, the code doesn't actually return anything or declare main as taking command line arguments. Not necessarily incorrect in some situations (e.g. embedded applications) but generally a good idea.
demagogue on 18/9/2010 at 20:03
Would have helped if I didn't just copy-paste that from the link steo posted. I'm sure you'll all be happy to know I use "/n" to end lines and "void" for main() too, (you know how much lawyers need good C++ skills), but couldn't be assed to fix it here.
Volitions Advocate on 18/9/2010 at 23:01
Interesting....
I always put using namespace std; before declaring any of my fuctions.
I always use int for main and return 0 at the end. It's just how I was taught.
Lizardfuel.. you have a textbook right? Any textbook worth its weight in paper in this field will have examples to go along with the explanations. It would take even less effort to just copy them out of the text than it would waiting on this bunch for a reply that might actually give you what you ask for. And everybody here has a point.
Brian The Dog on 19/9/2010 at 01:01
I never bother using namespace std - I always like to know which are my functions/classes (in their own namespace) and which are the ANSI/ISO standard ones. One thing I've always wondered in C++ - is there any reason to use "\n" at the end of a line rather than std::endl ?
VA's right, any beginner's textbook worth its salt will tell you how to do maths with entered into the program, usually around Chapter 2.
Xorak on 19/9/2010 at 04:07
In the time it took the OP to even wait for the first reply he could have easily written that program: three cins, three ints, the math formula and a cout. Good luck with the harder stuff, I really mean it. Programming is tough if you aren't interested at all in it.