I'm writing a calendar program and I need help with a function called getMonth().
It's supposed to return a single value as the output: the month number that the user entered. It also ensures that the month is in the acceptable range (1 ≤ month ≤ 12) . If the user enters a month outside that range, then getMonth() keeps prompting him or her until an acceptable value is found.
Here's what I came up with:
the problem is that whenever I enter in any number, regardless of whether it fits the parameters of 1 and 12, it goes through an infinite cycle.Code:int getMonth()
{
int month;
cout << "Enter a month number: ";
cin >> month;
for (month = 1; month = 12; month++)
{
int month;
if (month > 12)
cout << "Month must be between 1 and 12";
}
return month;
}
I DON'T KNOW WHAT TO DO!!!!
please help :)