I've been studying enums lately and decided to make a program with it to test the enum syntax and my first one worked. It was:
#include<iostream>
using namespace std;
int main()
{
enum daysinweek{
monday=0,
tuesday=1,
};
enum daysinweek enumerator=monday;
cout<<enumerator<<endl;
system("pause");
return 0;
}
It worked perfectly, by outputting 0, like it should.
Then I tried to step it up and make the program define enumerator with a user input of 0 or 1 using a switchcase. The code was:
#include<iostream>
using namespace std;
int main()
{
int whatday;
int enumerator;
cout<<"What day is it-monday or tuesday? (0 for monday, 1 for tuesday)"<<endl;
cin>>whatday;
enum daysinweek{
monday=0,
tuesday=1,
};
switch(whatday)
{
case 0:
enum daysinweek enumerator=monday;
break;
case 1:
enum daysinweek enumerator=tuesday;
break;
}
cout<<enumerator;
system("pause");
return 0;
}
But I got these error messages:
1>enum.cpp
1>.\enum.cpp(17) : error C2360: initialization of 'enumerator' is skipped by 'case' label
1> .\enum.cpp(15) : see declaration of 'enumerator'
1>.\enum.cpp(18) : error C2374: 'enumerator' : redefinition; multiple initialization
1> .\enum.cpp(15) : see declaration of 'enumerator'
1>.\enum.cpp(21) : error C2065: 'enumerator' : undeclared identifier
I want to know how i can have the user define the day while still using the enum type.