Lol, yes March has 31 days. I should have used the knuckle method to find that out.
Lol, yes March has 31 days. I should have used the knuckle method to find that out.
you guys are all blooldy legends first of all and thx for the enum method slingerland3g
but can someone explain to me how the enumeriatsaion method works
and can someone give me some tips on how to convert years into words>??? cause i have absolute no idea
Enumeration is like defining an integer type, but only allowing the values 0, 1, 2. If the user tries to assign anything other than a 0, 1, 2, you get an error.
It's useful for assigning descriptive names to certain values that a variable can take.Code:typedef enum { ENUMERATION_1, ENUMERATION_2, ENUMERATION_3 } enumeration; enumeration a; enumeration b;
so since i have to create a calender from january to decemeber
enumeration wont work eh cause it only works for intergers for 0, 1, 2 but not 3 onwards...
so what other methods can i use if i did to include integers from 0 to 12
Why do you say so? enum could include any integer you wantcause it only works for intergers for 0, 1, 2 but not 3 onwards
Why do you need 13 months?integers from 0 to 12
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
for marking an error code
hi guys im just wondering how to make an else if comment this is what i got so far....
if (month == January)
printf("Janurary has 31 days\n");
else if ((month == February)&& (((year%4==0 )&& (year%100!=0)) || ((year%400==0) && (year%100==0)&& (year%4==0))))
{ printf("February has 29 days\n");
}
else
{ printf ("February has 28 days\n");
}
However it does not work
use switch
Code:enum months {Jan,Feb,Mar,...} month; switch(month) { case Jan: ... break; case Feb: ... }
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
u mind explaining briefly about how switch works plz?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Post code within code tags! and indent properly.
Also use braces with all if/else statements or at least don't mix an if statement without braces with an else statement with braces!Code:if (month == January) { printf("Janurary has 31 days\n"); } else if ((month == February) && ( ((year%4 == 0 ) && (year%100 != 0)) || ((year%400 == 0) && (year%100 == 0) && (year%4 == 0)) ) ) { printf("February has 29 days\n"); } else { printf ("February has 28 days\n"); }
I've also re-aligned your if statement a bit, so you can see whether you're doing what you're intending to do.
QuantumPete
"No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
"Have you tried turning it off and on again?" - The IT Crowd
hi i sort of fixed it but don't know what i did wrong when i want the printf statement to be Feb has 29 days when it's a leap year... Code as follow: THX A LOT GUYS
switch(month)
{
case January:
printf("January has 31 days\n");
break;
case February:
printf("February has 28 days\n");
break;
case (((year%4==0 )&& (year%100!=0)) || ((year%400==0) && (year%100==0)&&
(year%4==0))) February:
printf("February has 29 days\n");
}
You need to put the condition to examine if it's a leap-year inside the case for February:
The case-label, e.g. Februry, must be constant, it can not be "an equation" - it MUST be something that the compiler can figure out at compile time into a simple number.Code:if (leap_year) ... 29 else ... 28
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
This might work by repetitive instruction:
use code tags.
http://cboard.cprogramming.com/showthread.php?t=25765
QuantumPete
"No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
"Have you tried turning it off and on again?" - The IT Crowd
Code:#include <stdio.h> int main() { int year, month; enum months{January = 1, February, March, April, May, June, July, August, September, October, November, December}; printf("Enter year and month:"); scanf("%d %d", &year, &month); if (((year%4==0 )&& (year%100!=0)) || ((year%400==0) && (year%100==0)&& (year%4==0))) { printf("has three hundred and sixty six (366) days\n"); } else { printf("has three hundred and sixty five (365) days\n"); } switch(month) { case January: printf("January has 31 days\n"); break; case February: printf("February has 28 days\n"); break; case (((year%4==0 )&& (year%100!=0)) || ((year%400==0) && (year%100==0)&& (year%4==0))) February: printf("February has 29 days\n"); } return 0; }