Newbies and Beginner Programmers come!

Started by
14 comments, last by ThomasSauder 20 years, 7 months ago
I would define an enum as a cross between a struct and a #define. What an enum does is define a numerical constant (const int) to a name like you can do with #define but all the constants are grouped together in a structure like way

for example:
enum Days{Monday = 0,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday //no comma needed for last entry};//now to use this we could have something like this:void PrintDay(Days CurDay){cout << "Today is:" << CurDay << endl;}//no when you call it like so:PrintDay(Monday);//it will print "Today is Monday" to the console


EDIT: just to clarify, all the values are incremented sequentially, so Tuesday would equal 2 etc but if the initial value of Monday is changed to say 10 then Tuesday would equal 11 etc. You can specify values for all of the entries in the enum if you want but most ppl just set the value of the first entry and let the compiler do the rest

[edited by - Spudder on September 25, 2003 6:15:54 PM]
Advertisement
And that's chapter one?... Shouldn't Ch1 be:
#include <iostream>using namespace std;int main(){  cout << "hello world!" << endl;  system("pause");  return 0;}


[edited by - WiseElben on September 25, 2003 7:06:34 PM]
quote:Original post by Spudder
I would define an enum as a cross between a struct and a #define. What an enum does is define a numerical constant (const int) to a name like you can do with #define but all the constants are grouped together in a structure like way

for example:
enum Days{Monday = 0,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday //no comma needed for last entry};//now to use this we could have something like this:void PrintDay(Days CurDay){cout << "Today is:" << CurDay << endl;}//no when you call it like so:PrintDay(Monday);//it will print "Today is Monday" to the console


EDIT: just to clarify, all the values are incremented sequentially, so Tuesday would equal 2 etc but if the initial value of Monday is changed to say 10 then Tuesday would equal 11 etc. You can specify values for all of the entries in the enum if you want but most ppl just set the value of the first entry and let the compiler do the rest

<SPAN CLASS=editedby>[edited by - Spudder on September 25, 2003 6:15:54 PM]</SPAN>


Tuesday would be equal to 1.. and cout << "Today is:" << CurDay << endl; would just print out a number, not the actual day as text.


I think the best place for beginners to learn is from a good book, of which there are plenty (consult the Books and software section of the website)
Like I said, it''s for beginners, not people completely new to the language, and if someone actually wants to learn, send me an e-mail and I''ll go through the code on a chat and explain it thoroughly.

But yea. Sams teach yourself C++ in 21 days, read up to classes. (12th chapter I think). Then read Accelerated C++, as Sams gets really stupid and hard to understand passed chapter 12 (i think)... its hard to understand if you''re a person who wants to know WHY it happens rather than "Just do it"
quote:Original post by ThomasSauder
Like I said, it''s for beginners, not people completely new to the language, and if someone actually wants to learn, send me an e-mail and I''ll go through the code on a chat and explain it thoroughly.

But yea. Sams teach yourself C++ in 21 days, read up to classes. (12th chapter I think). Then read Accelerated C++, as Sams gets really stupid and hard to understand passed chapter 12 (i think)... its hard to understand if you''re a person who wants to know WHY it happens rather than "Just do it"


Ummm the lack of Comments in your "Tutorials" is going to go against what you just said, you want to know why your doing what your doing, but with your code you don''t have a clue why your doing what your doing..

If you want to call it a tutorial then you need to explain whats happenning.. I don''t really see anyone being at a point where they would know how to #include something and know what using namespace std; if they don''t know how to do what your doing..

Its great that your trying to help, but I don''t know how much its going to help to just give people a bunch of code and say this takes input and displays with a border..

Just my 2 Cents

Please visit Turt99 Productions
FOLLOW ME ON TWITTER OR MY BLOG

This topic is closed to new replies.

Advertisement