Presentation is loading. Please wait.

Presentation is loading. Please wait.

Char ch; ch ‘L’‘X’‘V’‘I’ As in Roman numerals Want to give each a value, n say switch (ch) { case ‘I’:n = 1; break; case ‘V’:n = 5; break; … default:cout.

Similar presentations


Presentation on theme: "Char ch; ch ‘L’‘X’‘V’‘I’ As in Roman numerals Want to give each a value, n say switch (ch) { case ‘I’:n = 1; break; case ‘V’:n = 5; break; … default:cout."— Presentation transcript:

1 char ch; ch ‘L’‘X’‘V’‘I’ As in Roman numerals Want to give each a value, n say switch (ch) { case ‘I’:n = 1; break; case ‘V’:n = 5; break; … default:cout << “error”; break; } ch n = 1n = 5n = 10n = 50 ‘I’ ‘V’‘X’ ‘L’

2 If letter is ‘X’, ‘L’, ‘M’, ‘S’ switch (letter) { case ‘X’: statement 1; break; case ‘L’: case ‘M’: statement 2; break; case ‘S’: statement 3; break; default:statement 4; } statement 5;

3 Problem: Given as input 3 integers representing a date (MM/DD/YYYY) output the date of the next day. int day, month, year; 2/17/2001  2/18/2001 1/31/2001  2/1/2001 12/31/2001  1/1/2002 2/28/2001  3/1/2001 Need days_in_month

4 switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days_in_month = 31; break; case 4: case 6: case 9: case 11: days_in_month = 30; break; case 2:if () days_in_month = 28; else days_in_month = 29; break; }

5 switch (month) { case 1: case 3: … case 12: days_in_month = 31; break; … } If (day == days_in_month) { day = 1; if (month == 12) { month = 1; year++; } else month++; } else day++;


Download ppt "Char ch; ch ‘L’‘X’‘V’‘I’ As in Roman numerals Want to give each a value, n say switch (ch) { case ‘I’:n = 1; break; case ‘V’:n = 5; break; … default:cout."

Similar presentations


Ads by Google