Leap Year Problem...
-
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
-
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
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 )
-
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
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 }
modified on Monday, April 6, 2009 5:07 AM