17th Week Item 4-date structure (the day ordinal of the year)

Source: Internet
Author: User

Defines a struct variable (including year, month, and day) that requires the input of the year, month, and day, which is the day ordinal of the year.

/** Copyright (c) 2014, Yantai University School of Computer * All right reserved.* Shao * file: demo.cpp* finish: December 16, 2014 * version number: v1.0*/#include <iostream    >using namespace std;struct date{int year;    int month; int day;};    int main () {date date;    cout<< "input year,month,day:";    cin>>date.year>>date.month>>date.day;    int days;        Calculate days switch (date.month) {case 1:days = Date.day;    Break        Case 2:days = Date.day + 31;    Break        Case 3:days = Date.day + 59;    Break        Case 4:days = Date.day + 90;    Break        Case 5:days = Date.day + 120;    Break        Case 6:days = date.day + 151;    Break        Case 7:days = date.day + 181;    Break        Case 8:days = date.day + 212;    Break        Case 9:days = date.day + 243;    Break        Case 10:days = date.day + 273;    Break        Case 11:days = date.day + 304;    Break        Case 12:Days = Date.day + 334;    Break } if ((date.year% 4 = = 0 && date.year% 100! = 0) | |    (date.year% = = = 0 && date.year 100 = = 0))    {if (date.month>2) days--; } cout<<date.month<< "Month" <<date.day<< "Day is" <<date.year<< "year" <<days< < "day."    <<endl; return 0;}
Operation Result:


@ Mayuko

17th Week Item 4-date structure (the day ordinal of the year)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.