Started By
Message

re: C# Help. I always have dumb face on.

Posted on 2/4/15 at 3:38 pm to
Posted by Hu_Flung_Pu
Central, LA
Member since Jan 2013
22232 posts
Posted on 2/4/15 at 3:38 pm to
1. Implement a console application that does the following: Prompt and read in two DateTime values from the user. Calculate and output a) if the first date is before the second or not; b) the difference in hours between the two dates, and c) if the second date falls in a leap year.

2. Write a console program for the following (you can add this to the same program as above if desired). Prompt the user to enter a value.
• If it is a date, write it in long date format (ex.: February 11, 2015).
• If it is numeric, write it twice (on the same line), once as a currency value, and the second in “9,990.000” style format.

3. Write a form application that does all the following (have a separate button for each on the form):
a. Given a number of days N that a user specifies in a textbox, calculate and output to a label the date N days from the current date (in short date format). N can be negative, but must be numeric. Validate user input is numeric before attempting the calculation.
b. Without using the C# date functions, write the number of days in a month to a label given a user specified month and year. In addition to the basic rule of "30 days hath September, April, June, and November; All the rest have thirty-one except February (which has 28)", there are the rules concerning leap years (which adds an extra day):
A year is a leap year if it is divisible by 4
EXCEPT when the year is a centennial
UNLESS it is also divisible by 400.
Also write the result from the C# DateTime .IsLeapYear() function to a separate label.


I was eventually able to do 1 and 2 but needed some help. 3b is where I am stuck. Teacher wants us to do cases.
Posted by Doldil
The Ham
Member since Jan 2010
6214 posts
Posted on 2/4/15 at 3:49 pm to
Well, I'm gonna be perfectly honest with you...it's been damn near 8 years since I did something like that, so I'm not going to be of much help. I think you can read up on case/switch statements to kind of see how to write one...but as others have said, you're just going to have to play with it to really understand it.

Also, if you're having problems with your code not working, make sure your using your step-through options to go through the code line by line to see where it's breaking...or to help understand why it's doing what it's doing.

TL;DR sorry, can't help much
Posted by MamouTiger65
Baton Rouge, La
Member since Oct 2007
799 posts
Posted on 2/4/15 at 4:00 pm to
Sounds like you are looking for something like this.

int days = 0;


switch (month)
{
case "September":
days = 30;
break;
case "April":
days = 30;
break;
case "June":
days = 30;
break;
case "November":
days = 30;
break;
case "February":
if((year % 4 == 0 && year % 100 != 0) || (year % 4 == 0 && year % 400 == 0))
{
days = 29;
}
else
{
days = 28;
}
break;
default:
days = 31;
break;
}
first pageprev pagePage 1 of 1Next pagelast page
refresh

Back to top
logoFollow TigerDroppings for LSU Football News
Follow us on Twitter, Facebook and Instagram to get the latest updates on LSU Football and Recruiting.

FacebookTwitterInstagram