Troudeloup
asked on
[noob][c++] what is enum and how do I use it?
what is enum and how do I use it?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
#include <iostream>
using namespace std;
enum e_usflcnst{
CATLIFE_FACTOR = 7
};
int main()
{
int age;
cout << "Enter your age: ";
cin >> age;
age /= CATLIFE_FACTOR;
cout << "If you were cat, you would be " << age << endl;
}
this makes sense,
but what I don't undersrtand it, why not just use a variable for the factor?
also, what role does e_usflcnst play here?
using namespace std;
enum e_usflcnst{
CATLIFE_FACTOR = 7
};
int main()
{
int age;
cout << "Enter your age: ";
cin >> age;
age /= CATLIFE_FACTOR;
cout << "If you were cat, you would be " << age << endl;
}
this makes sense,
but what I don't undersrtand it, why not just use a variable for the factor?
also, what role does e_usflcnst play here?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i don't understand,
I get it that raidbowcolors is a enum type (just like int and double, it's a type of variable ) with elements (colors)
but then how are you using it?
I get it that raidbowcolors is a enum type (just like int and double, it's a type of variable ) with elements (colors)
but then how are you using it?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
is it like a way to use strings without having to use string variables?
so a type rainbow can have only those variants of colors , can I alter rainbow afterwards?
so a type rainbow can have only those variants of colors , can I alter rainbow afterwards?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
also, I have to assign only those elements I already define in the enum type right?
for instance I can't do
rainbow trafficlights = silver
also, I don't need to quote colors?
for instance I can't do
rainbow trafficlights = silver
also, I don't need to quote colors?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you all SO much !
ASKER