The basics of programming in c++ for beginners

A task. Calculate the number of days between dates.

The task is simple: Find the number of days between two dates. Provide account leap years.

To practice the two options:

  1. One of the boundary dates described only a year. That is, the start date is entered in full (for example 25.12.2015), and the second only a year (for example 2016). It counts the days before 01.01.2016
  2. Both the date of full – describes day month year.

Here is an example of a, partially crucial first simplified version:

Here the function DaysCount() It receives in the first three parameters of the start date (year, month, day) and the last parameter boundary (year, 1-th day of January,)

Solve any possible way, even though the cycle with something else. But the decision of the second embodiment does not show :) Let it be homework. Good luck!

Questions to ask in the comments

15 thoughts on “A task. Calculate the number of days between dates.

  1. please help to write a program

    Determine how many days in a year (Total 12 months, each has a certain number of days) using a function for, and one-dimensional array

  2. [code]#include “stdafx.h”
    #include
    using namespace std;
    int main()
    {
    int monthM[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
    char ch;
    int end, day, month, year, sum = 0;
    setlocale(LC_ALL, “rus”);
    cout <> day >> ch >> month >> ch >> year;
    cout<> end;

    for (int i = month + 1;i <= 11;i ) sum += monthM[i];
    sum += monthM[month]+day + (end – year) * 365;
    for (int i = year+1; i < end; i )
    if (i % 400 == 0 || i % 4 == 0) sum++;//Wikipedia is written, that in the Gregorian calendar leap year every 4th + each 400y
    if ((year % 400 == 0 || year % 4 == 0) && month < 4) sum++; //starting year checking separately, tk. even if it is a leap year, we can not catch 29fevralya during
    cout << "\nВ этом промежутке " << sum << "дней!";
    return 0;
    }
    [/code]

Leave a Reply to Dmitriy Cancel reply

Your email address will not be published. Required fields are marked *