How can we help?

You can also find more resources in our Help Center.

3 terms

C++ Programming in easy steps: Beginners 7 Part 4

Batten down the hatches! Were almost there!
STUDY
PLAY
typedef enum { NEGATIVE , POSITIVE } charged ;
Give this constant the nickname "charged".

enum { NEGATIVE , POSITIVE } ;

If the statement starts with the keyword typedef, a name can be added on the end.

Note: This will make it easier, to use the constant.
cout << "Neutral wire: " << neutral << endl ;
These two statements have been declared as constants.

typedef enum { NEGATIVE , POSITIVE } charged ;
charged neutral = NEGATIVE , live = POSITIVE ;

The constant NEGATIVE has been named "neutral".
And the POSITIVE as "live".
-------------------------------------------------------------------------

Declare a statement that will output the following as text:
"Neutral wire: "

To reference the NEGATIVE constant, use it's given name,
"neutral".

The constant will appear, alongside the text. As follows:
Neutral wire: 0
cout << "Live wire: " << live << endl ;
These two statements have been declared as constants.

typedef enum { NEGATIVE , POSITIVE } charged ;
charged neutral = NEGATIVE , live = POSITIVE ;

The constant NEGATIVE has been named "neutral".
And the POSITIVE as "live".
-------------------------------------------------------------------------

Declare a statement that will output the following as text:
"Live wire: "

To reference the POSITIVE constant, use it's given name,
"live".

The constant will appear, alongside the text. As follows:
Live wire: 1

Note: The numbers are referenced in the constants.
Starting from zero and up.