CHAPTER 5
Decision and loop statements
73
while (month < 1 || month > 12);
return month;
}
3.
Modify the GetDay function as follows, which forces the user to type a valid day:
int GetDay(int year, int month)
{
int day = 0;
int maxDay;
// Calculate maxDay, as before (code not shown here) … … …
do
{
Console::Write("Day [1 to ");
Console::Write(maxDay);
Console::Write("]? ");
String ^input = Console::ReadLine();
day = Convert::ToInt32(input);
}
while (day < 1 || day > maxDay);
return day;
}
4.
Build and run the application.
5.
Try to type an invalid month. The application keeps asking you to enter another month until
you type a value between 1 and 12, inclusive.
6.
Try to type an invalid day. The application keeps asking you to enter another day until you
type a valid number (which depends on your chosen year and month).
Do'stlaringiz bilan baham: |