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?

Recommended Answers

All 3 Replies

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?

iraqi4life,

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;
break;

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

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

change 'other' to default' (",).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.