输出星期几两次之间的时间

问题描述 投票:0回答:1
void DayClose(int k, Date d1, Date d2) {
    int numberOfDays = thisIsMagic(d2.year, d2.month, d2.day) - thisIsMagic(d1.year, d1.month, d1.day);
    int i = d1.day;
    if (d1.month == 1 || d1.month == 3 || d1.month == 5 || d1.month == 7 || d1.month == 8 || d1.month == 10 || d1.month == 12) {
        if (d1.month < d2.month) {
            for (i;i < 31;i++) {
                if (get_day(i, d1.month, d1.year) == k) {
                    cout << "that day" << endl;
                    cout << d1.year << " " << d1.month << " " << i;
                    break;
                }
                if (i == 31) {
                    d1.month++;
                    i = 1;
                }
            }
        }
    }
    else if (d1.month == 4 || d1.month == 6 || d1.month == 9 || d1.month == 12) {
        if (d1.month < d2.month) {
            for (i;i < 30;i++) {
                if (get_day(i, d1.month, d1.year) == k) {
                    cout << "that day" << endl;
                    cout << d1.year << " " << d1.month << " " << i;
                    break;
                }
                if (i == 30) {
                    d1.month++;
                    i = 1;
                }
            }
        }
    }
    else if (d1.month == 2) {
        if (d1.month < d2.month) {
            for (i;i < 28;i++) {
                if (get_day(i, d1.month, d1.year) == k) {
                    cout << "that day" << endl;
                    cout << d1.year << " " << d1.month << " " << i;
                    break;
                }
                if (i == 28) {
                    d1.month++;
                    i = 1;
                }
            }
        }
    }
    int numberOfDays2 = thisIsMagic(d2.year, d2.month, d2.day) - thisIsMagic(d1.year, d1.month, i);
    int dis = numberOfDays - numberOfDays2;
}

考试d1:2020年4月1日。并输入k = 2

函数get_day将检查最近的日期是否为星期一。 for循环将在(i / month / year)= Monday时终止。这意味着它会破裂。

d2:03 05 2020

2次之间的距离(d2-d1):32

2次之间的距离(d2 -di):27

我想每个星期一打印两次之间的距离(d2-d1)

考试:

05 4 2020
12 04 2020
19 04 2020
26 04 2020
03 05 2020

但是如果我再次循环播放。它太长了,也许是错误的:<

你能让我写信吗?

此功能要求在星期一(或星期二,...)之间打印两次]

void DayClose(int k,Date d1,Date d2){int numberOfDays = thisIsMagic(d2.year,d2.month,d2.day)-thisIsMagic(d1.year,d1.month,d1.day); int i = d1.day;如果(d1.month == 1 || d1.month == ...

c++ date
1个回答
0
投票

最好使用内置的日期和时间结构和函数来实现您要执行的操作。您可以在这里Date and Time

© www.soinside.com 2019 - 2024. All rights reserved.