标题:请问计算星期几的程序怎么编,最简单的那种?
只看楼主
梦在深巷
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2019-4-20
结帖率:0
已结贴  问题点数:20 回复次数:2 
请问计算星期几的程序怎么编,最简单的那种?
比如告诉你今天周三,再过四天是周几。
搜索更多相关主题的帖子: 计算 今天 
2019-04-20 13:58
梦在深巷
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2019-4-20
得分:0 
小朋友就学过没几个代码
2019-04-20 21:09
ZJYTY
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:4
帖 子:92
专家分:700
注 册:2018-12-20
得分:20 
程序代码:
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int today,after;
    char *week[7] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

    do 
    {
        cout << "Today is week(1-7) : ";
        cin >> today;
        while (!getchar());
        if (today >= 1 && today <= 7){
            cout << "after : ";
            cin >> after;
            while (!getchar());

            int valueafter = after % 7;

            int temp = today + valueafter - 1;
            if (temp > 7){
                temp -= 7;
            }

            cout << "Today is " << week[today - 1] << ",after " << after << " days is " << week[temp] << endl;
        }
        if (0 == today){
            break;
        }
        
    } while (1);
    
    return 0;
}

-------------------------------若有不当之处,敬请谅解-------------------------------
2019-04-21 10:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-494307-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022359 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved