Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   how can i use switch in this ? (http://www.go4expert.com/forums/i-switch-t18541/)

cooop 15Jul2009 00:06

how can i use switch in this ?
 
Write a program to get a date from the user in the format day/month/year. Tip: use extra variables to read the /. The program should check the three parts of the date (day, month, year), and print a warning message for any part of the date that is wrong. If the whole date is correct, it should print a message saying that the date is valid. The normal rules for dates apply: valid days are from 1 to 28, 29, 30, or 31 (depending on the month and on whether the year is a leap year. You might want to use a switch statement to perform this task.); valid months are from 1 to 12; valid years start from 1582 (the year in which our current calendar system started). The rule for deciding if a year is a leap year is as follows: a year evenly divisible by 4 is a leap year; except if the year is evenly divisible by 100, in which case it is not a leap year; except if the year is evenly divisible by 400, in which case it is a leap year.
Examples:
./date_check
Enter a date (d/m/y): 29/2/2002
The day 29 is not valid!


./date_check
Enter a date (d/m/y): 32/15/1002
The year 1002 is not valid!
The month 15 is not valid!
The day 32 is not valid!


./date_check
Enter a date (d/m/y): 20/9/2002
The given date is valid.

xpi0t0s 15Jul2009 05:12

Re: how can i use switch in this ?
 
How far have you got and where are you stuck? We won't write the code for you, but we will help.

fob500 15Jul2009 10:09

Re: how can i use switch in this ?
 
Hey coop.Are You posting your school homework ??:nonod:
I suggest you try out these programs yourself and then ask for help.Trust me it would help you to learn.Still I think a lot of members would be willing to help if you try atleast and paste some code.No one will do it for you.Also I guess you are starting with c/c++
I suggest you see this http://www.codersource.net/codersour...ogramming.html
.It would help you with the basics.
Otherwise if you don't really want to do that I suggest you search google there are thousands of programs(maybe if you are lucky you might find a program which does similar to what you want to do) this way you'll have a better chance completing your program(if you really dont want to do it yourself).Hope that helped


All times are GMT +5.5. The time now is 10:23.