Been all through books and tutorials trying to learn how to code the while loop, char, switch and bool. in one program Loop is stuck. If wrong letter is entered, should ask user to reprompt, otherwise the function returns the number, but will not leave the loop. The problem may be the test condition- not sure how to correct or what to do next
#include<iostream>
char months (char);
using namespace std;
int main()
{
char Season,time;
Season = months(time);
cout << endl;
cout <<Season;
cout<<endl<<endl;
cout << " Press [enter] to exit" <<endl;
cin.ignore(); //needed because of keyboard input
cin.get ();
return 0;
}
char months (char monthNumber)
{
char Q;
char season= Q;
bool valid =false;
do{
cout << endl;
cout << " Enter a letter ";
cin >> monthNumber;
cout << endl;
while( monthNumber=='Q')
{cout << " Invalid month, enter another month ";
cin >> monthNumber;
cout << endl;}
} while ('Q' != valid);
switch ( monthNumber) {
case 'F': case 'f':
monthNumber = 2; valid = true;
cout << endl <<endl;
break;
case 'S':case 's':
monthNumber = 9; valid = true;
cout << endl;
break;
case 'O': case 'o':
monthNumber = 10; valid = true;
cout << endl;
break;
case 'N': case 'n':
monthNumber = 10;valid = true;
cout << endl;
break;
case 'D':case 'd':
monthNumber = 12; valid = true;
cout << endl;
break;
return monthNumber;
}
cout<<endl<<endl;
cout << "Press [enter] to exit" <<endl;
cin.ignore(); //needed because of keyboard input
cin.get();
return 0;
}