/* (Start of program header annotation)
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: enter a date, which is the day of the year.
* Author: Lei hengxin
* Completion date: January 1, September 09, 2012
* Version No.: V1.0
* Description of tasks and Solutions
* Input description:
* Problem description:
* Program output:
* End the comment in the program Header
*/
[Csharp]
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace ConsoleApplication_do_while
{
Class Program
{
Static void Main (string [] args)
{
Console. WriteLine ("| ---------------------------------------------------------------- | ");
Console. WriteLine ("| this is a program that" enter a date and calculate that date is the day of the year "| ");
Console. WriteLine ("| ---------------------------------------------------------------- | ");
Console. WriteLine ();
Console. WriteLine ("you need to enter a date ...");
Console. WriteLine ();
Console. Write ("you need to enter the year :");
Int year = int. Parse (Console. ReadLine ());
Console. WriteLine ();
Console. Write ("you need to enter the month :");
Int month = int. Parse (Console. ReadLine ());
Console. WriteLine ();
Console. Write ("what date do you need to enter ?) :");
Int date = int. Parse (Console. ReadLine ());
Console. WriteLine ();
Console. Write ("{0} year {1} month {2} is the day of the year", year, month, date );
Bool B = Leap_Common_year (year); // determines whether the year is a year or a leap year.
Switch (month) // judge the month
{
Case 1: month_1 (date); break; // determine the day Based on the date
Case 2: month_2 (date); break;
Case 3: month_3 (date, B); break;
Case 4: month_4 (date, B); break;
Case 5: month_5 (date, B); break;
Case 6: month_6 (date, B); break;
Case 7: month_7 (date, B); break;
Case 8: month_8 (date, B); break;
Case 9: month_9 (date, B); break;
Case 10: month_10 (date, B); break;
Case 11: month_11 (date, B); break;
Case 12: month_12 (date, B); break;
Default: Console. WriteLine ("the month you entered is incorrect..."); break;
}
Console. ReadKey ();
}
Static bool Leap_Common_year (int year) // judge whether the year is a year or a leap year.
{
Bool B;
If (year % 4 = 0 & amp; year % 100! = 0)
{
B = false;
}
Else
{
B = true;
}
Return B;
}
Static void month_1 (int date)
{
Console. Write ("{0} Days. ", Date );
}
Static void month_2 (int date)
{
Int d;
D = 31 + date;
Console. Write ("{0} Days", d );
}
Static void month_3 (int date, bool B)
{
Int d;
If (B)
{
D = 31 + 28 + date;
}
Else
{
D = 31 + 29 + date;
}
Console. Write ("{0} Days", d );
}
Static void month_4 (int date, bool B)
{
Int d;
If (B)
{
D = 31 + 28 + 31 + date;
}
Else
{
D = 31 + 29 + 31 + date;
}
Console. Write ("{0} Days", d );
}
Static void month_5 (int date, bool B)
{
Int d;
If (B)
{
D = 31 + 28 + 31 + 30 + date;
}
Else
{
D = 31 + 29 + 31 + 30 + date;
}
Console. Write ("{0} Days", d );
}
Static void month_6 (int date, bool B)
{
Int d;
If (B)
{
D = 31 + 28 + 31 + 30 + 31 + date;
}
Else
{
D = 31 + 29 + 31 + 30 + 31 + date;
}
Console. Write ("{0} Days", d );
}
Static void month_7 (int date, bool B)
{
Int d;
If (B)
{
D = 31 + 28 + 31 + 30 + 31 + 30 + date;
}
Else
{
D = 31 + 29 + 31 + 30 + 31 + 30 + date;
}
Console. Write ("{0} Days", d );
}
Static void month_8 (int date, bool B)
{
Int d;
If (B)
{
D = 31 + 28 + 31 + 30 + 31 + 30 + 31 + date;
}
Else
{
D = 31 + 29 + 31 + 30 + 31 + 30 + 31 + date;
}
Console. Write ("{0} Days", d );
}
Static void month_9 (int date, bool B)
{
Int d;
If (B)
{
D = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + date;
}
Else
{
D = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + date;
}
Console. Write ("{0} Days", d );
}
Static void month_10 (int date, bool B)
{
Int d;
If (B)
{
D = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + date;
}
Else
{
D = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + date;
}
Console. Write ("{0} Days", d );
}
Static void month_11 (int date, bool B)
{
Int d;
If (B)
{
D = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 31 + date;
}
Else
{
D = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 31 + date;
}
Console. Write ("{0} Days", d );
}
Static void month_12 (int date, bool B)
{
Int d;
If (B)
{
D = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 31 + 31 + 30 + date;
}
Else
{
D = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 31 + 31 + 30 + date;
}
Console. Write ("{0} Days", d );
}
}
}
Running result:
Problem: I found that in the switch statement, break must be added after default; otherwise, the program reports an error.
This is a little different from C ++.