Greeting Codeguru World.
I have a question related to switch statement, which the switch in class employee2 gives me error at output. Program compiled well. I am using Code::Block Compiler V10.5. I have created object of class employee2 in main() function to get data from user, store it and display it. At the output, Compiler doesn't show actual output what i am expecting. The fun thing is my compiler printed emocion like (:D), where (hourly/monthly/weekly) was supposed to print.
Is there any mistake in my Coding..
Note : I am beginner in (OOP C++ Programming) (I guess i might made some common error, which i can't find myself)
Code:#include <iostream>
using namespace std;
enum period {hourly,weekly,monthly};
class employee2
{
private :
char ch;
period x;
double compensation;
public :
void getdata()
{
cout <<"\nEnter Compensation : "; cin >> compensation;
cout <<"\nEnter Period :";
cout <<"\nPress 'h' for hourly"
<<"\nPress 'w' for weekly"
<<"\nPress 'm' for Monthly";
cin >> ch;
switch(ch)
{
case 'h' : x = hourly; break;
case 'w' : x = weekly; break;
case 'm' : x = monthly; break;
}
switch(x)
{
case 0 : ch = hourly; break;
case 1 : ch = weekly; break;
case 2 : ch = monthly; break;
default : cout << "Unknown Key!";
}
}
void putdata() const
{
cout << "\nPayment Period is " << ch << '\n';
}
};
Expecting some suggestion..
Regards
Basanta

