I have this bit of code:

case 1:

		case 3:

		case 5:

		case 7:

		case 8:

		case 10:

		case 12:

			day = 31;

Does this mean the values 3,5,7,8,10,12 can only be day=31?
How can I make it so only the Max value is 31? So it can equal 31 or less?

7 Years
Discussion Span
Last Post by Eric Cute

It means if the value of the variable you are using in comparison is 1, 3, 5, 7, 8, 10, or 12, it would make these case statements true. As a result, the 'day' variable is assigned to 31.

If you are assigning a value to a variable, you assign only 1 value to it. If you want to compare, you could use if-else, switch, or comparison operator.

Anyway, what the "Max" value you are talking about in your post? Even though, I can understand the portion of code you gave, the portion of the code is not really completed. What are you really looking for from the code?



I think you are trying to assign the days of the month and you want that since max no of days in a month is 31, 31 should be max value.

Since you are assigning a constant to the day variable, then you should have full control of the max value.

maybe you want to use this code instead:

case 2: /* for february  */
day = 28;

case 4: /* april, june, sepetember november */
case 6:
case 9:
case 11:
day = 30;

other: /* for all other months */
day = 31;

Edited by Eric Cute: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.