Good Afternoon,
I'm having trouble with loops that deal with enumeration.
So far I have this code
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main( )
{
//enumerate type definition
enum weekDays {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,Sunday};
//variable declarations
weekDays myDays; //to deal with weekDays datatype
string day; //C++ string object, to get the day
char anotherDay[50]; //C-string var, to get the day as a C-string
char choice, //for choice of C++ strings or C-string;
option; //a flag to stop the loop
//loop foevever to play the program until the user stops
while (true)
{
//play with C++ strings or C-strings
cout<<"Want to play C++ strings or C-strings (y for C++ strings /n for C strings)? => "<<endl;
cin>>choice;
if (choice == 'y' || choice == 'Y') //for C++ strings
{
//get a day via C++ string object
cout<<"Enter a week day => ";
cin>>day;
//covert string week day to enumerated weekDays value
if (day == "Monday")
{
myDays = Monday;
cout<< "The day of the week that you entered is: " << day << endl;
}
else if (day == "Tuesday")
{
myDays = Tuesday;
cout<< "The day of the week that you entered is: " << day << endl;
}
//For you: finish the rest of conversion
/********** Write Your Code here *************/
else if (day == "Wednesday")
{
myDays = Wednesday;
cout<< "The day of the week that you entered is: " << day << endl;
}
else if (day == "Thursday")
{
myDays = Thursday;
cout<< "The day of the week that you entered is: " << day << endl;
}
else if (day == "Friday")
{
myDays = Friday;
cout<< "The day of the week that you entered is: " << day << endl;
}
else if (day == "Saturday")
{
myDays = Saturday;
cout<< "The day of the week that you entered is: " << day << endl;
}
else if (day == "Sunday")
{
myDays = Sunday;
cout<< "The day of the week that you entered is: " << day << endl;
}
else
cout<< "not a valid day. "<<endl;
}
//this part is to play with C-strings
else
{
//get a day via C string object
cout<<"Enter a week day => ";
cin>>anotherDay;
//covert string week day to enumerated weekDays value
if (strcmp(anotherDay, "Monday") == 0)
myDays = Monday;
else if (strcmp(anotherDay, "Tuesday") == 0)
myDays = Tuesday;
//For you: finish the rest of conversion
/********** Write Your Code here *************/
else
cout<< "not a valid day. "<<endl;
}
//now play with enumerated type value
switch (myDays)
{
case Monday:
cout<<"Monday is not a study day. "<<endl;
cout<<"coz I am still sleepy." <<endl;
break;
case Tuesday:
cout<<"Oh, Geez, Tuesday IS a studyday."<<endl;
break;
//This is for you: Complete the rest of the cases, including the default case.
/************ Write Your Code here ***********************************/
}
//This part is for you: Ask the user whether to continue the play or not
/************ Write Your Code here *********************************/
}
//well done and exit
return 0;
}