The assignment is to output the months of the year depending on the first, second, and third character from the user. Everything seems to run fine except for case 'M' or 'm". Because the second letter is already going to be an 'A', the assignment asks that we read in the next two letters from the user. Such as,
'ar' for March or 'ay' for May. So when I enter the next to letters, either 'ar' or 'ay', it outputs the default message "unknown month".
#include <iostream>
#include <iomanip>
usingnamespace std;
/*********************************************************
*********************************************************/
int main()
{
char answer, anest, jnest, jujunest, manest1, manest2;
cout << "Please enter the first letter of a month: " << endl;
cin >> answer;
cout << endl;
switch (answer) { // outter nested switch
case'F':
case'f':
cout << "The month is February" << endl;
break;
case'S':
case's':
cout << "The month is September" << endl;
break;
case'O':
case'o':
cout << "The month is October" << endl;
break;
case'N':
case'n':
cout << "The month is November" << endl;
break;
case'D':
case'd':
cout << "The month is December" << endl;
break;
case'A':
case'a':
cout << "Please enter the second letter of the month: " << endl;
cin >> anest;
switch (anest) { // April and August inner nest
case'P':
case'p':
cout << "The month is April" << endl;
break;
case'U':
case'u':
cout << "The month is August" << endl;
break;
default:
cout << "Unknown Month" << endl;
} // end of April August inner nest
break;
case'J':
case'j':
cout << "Please enter the second letter of the month: " << endl;
cin >> jnest;
switch (jnest) { // January June July inner nest
case'A':
case'a':
cout << "The month is January" << endl;
break;
case'U':
case'u':
cout << "Please enter the third letter of the month: " << endl;
cin >> jujunest;
switch (jujunest) { // July June double inner nest
case'L':
case'l':
cout << "The month is July" << endl;
break;
case'N':
case'n':
cout << "The month is June" << endl;
break;
default: cout << "Unknown Month" << endl;
} // end of July June double inner nest
break;
} // end of January June July inner nest
break;
case'M':
case'm':
cout << "Please enter the next two letters of the month: " << endl;
cin >> manest1, manest2;
switch (manest1) { // March May inner nest
case'A':
case'a':
switch (manest2) { // March May double inner nest
case'R':
case'r':
cout << "The month is March" << endl;
break;
case'Y':
case'y':
cout << "The month is May" << endl;
break;
default:
cout << "Unknown Month" << endl;
)
} // end of March May double inner nest
break;
default:
cout << "Unknown Month" << endl;
} // end of March May inner nest
break;
default: cout << "Unknown Month" << endl;
} // end of outer nest
cout << endl << endl;
system("PAUSE");
return 0;
}