Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Leap Year Problem...

Leap Year Problem...

Scheduled Pinned Locked Moved C#
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sah496
    wrote on last edited by
    #1

    Hello everybody, I am having a problem to solve the following c# exercise: You will take into account that February can be 29 days if it is during a leap year. Do NOT change the implementation of date_convert. Instead, add additional code in your main so that before you display the output of the method, if the month entered by the user is February, prompt the user for the year, and then use IsLeap to check the year and adjust the output of date_convert accordingly. Write appropriate method calls and statements within your main so that the console session may look as follows: A valid console session may look as follows: Please enter a month: March The number of days in March is 31 Another session may look as follows: Please enter a month: february Please enter a year: 2007 The number of days in February is 28 Another session may look as follows: Please enter a month: february Please enter a year: 2000 The number of days in February is 29 If anybody can help me to solve the problem then i will be very greatfull. Syed

    C A 2 Replies Last reply
    0
    • S sah496

      Hello everybody, I am having a problem to solve the following c# exercise: You will take into account that February can be 29 days if it is during a leap year. Do NOT change the implementation of date_convert. Instead, add additional code in your main so that before you display the output of the method, if the month entered by the user is February, prompt the user for the year, and then use IsLeap to check the year and adjust the output of date_convert accordingly. Write appropriate method calls and statements within your main so that the console session may look as follows: A valid console session may look as follows: Please enter a month: March The number of days in March is 31 Another session may look as follows: Please enter a month: february Please enter a year: 2007 The number of days in February is 28 Another session may look as follows: Please enter a month: february Please enter a year: 2000 The number of days in February is 29 If anybody can help me to solve the problem then i will be very greatfull. Syed

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      This is your homework. What have you done to solve it ? Are you allowed to use the DateTime class ?

      Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

      1 Reply Last reply
      0
      • S sah496

        Hello everybody, I am having a problem to solve the following c# exercise: You will take into account that February can be 29 days if it is during a leap year. Do NOT change the implementation of date_convert. Instead, add additional code in your main so that before you display the output of the method, if the month entered by the user is February, prompt the user for the year, and then use IsLeap to check the year and adjust the output of date_convert accordingly. Write appropriate method calls and statements within your main so that the console session may look as follows: A valid console session may look as follows: Please enter a month: March The number of days in March is 31 Another session may look as follows: Please enter a month: february Please enter a year: 2007 The number of days in February is 28 Another session may look as follows: Please enter a month: february Please enter a year: 2000 The number of days in February is 29 If anybody can help me to solve the problem then i will be very greatfull. Syed

        A Offline
        A Offline
        akhilonly007
        wrote on last edited by
        #3

        hey sah496 this will give u days in month according to month no u have passed to <pre> public int DaysInMonth(int nMonth) { int nDays = 0; switch (nMonth) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: nDays = 31; break; case 4: case 6: case 9: case 11: nDays = 30; break; case 2: int nDay=1; int nYear=GetYear(); DateTime oDate; oDate=Convert.ToDateTime(nDay.ToString()+ "-" + nMonth.ToString() + "-" + nYear.ToString() ,"dd-mm-yyyy"); if (DateTime.IsLeapYear(nYear)) { nDays = 29; } else { nDays = 28; } break; } return nDays; } public int GetYear() { // read year and return }

        akhilonly007@gmail.com

        modified on Monday, April 6, 2009 5:07 AM

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups