|
-
July 26th, 2012, 08:04 AM
#10
Re: Switch Output Error
 Originally Posted by basanta
The fun thing is my compiler printed emocion like (  ), where (hourly/monthly/weekly) was supposed to print.
Nope, you won't get the program to print one of the strings "hourly", "monthly" or "weekly" unless you tell it to.
An enum will internally be an integer, so everytime you write in your code hourly it will be replaced by 0, weekly by 1, etc. To print out the key, you need to switch again:
Code:
void print_period(period p) {
switch(p) {
case hourly: cout << "hourly"; break;
case weekly: cout << "weekly"; break;
case monthly: cout << "monthly"; break;
default: cout << "unknown";
}
}
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Please read Information on posting before posting, especially the info on using [code] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|