how can i use switch in this ?

Discussion in 'C' started by cooop, Jul 14, 2009.

  1. cooop

    cooop New Member

    Joined:
    Jul 8, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    How far have you got and where are you stuck? We won't write the code for you, but we will help.
     
  3. fob500

    fob500 New Member

    Joined:
    Jul 12, 2009
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice