foldless777 2022-10-11 11:58 采纳率: 60%
浏览 49
已结题

判断某年某月某日是这一年第几天

判断某年某月某日是这一年的第几天 程序未报错 不知道为什么结果一直不对

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
    int year,month,day,a,b,c,d;
    a==0;
    b==0;
    c==0;
    d==0;
    a==(month-1)*31+day+29;
    b==(month-1)*30+day+29;
    c==day;
    d==31+day;
    cout<<"Input year,month,day: "<<endl;
    cin>>year>>month>>day;
    if(year%4==0&&year%100!=0||year%100==0)
      switch(month){
      case 1:
      cout<<"Days of year: "<<c;
      break;
      case 3:
      case 5:
      case 7:
      case 8:
      case 10:
      case 12:
      cout<<"Days of year: "<<a;
      break;
      case 4:
      case 6:
      case 9:
      case 11:
      cout<<"Days of year: "<<b;
      break;
      case 2:
      cout<<"Days of year: "<<d;
      break;
      }
      else 
          switch(month)
          {
              case 1:
      cout<<"Days of year: "<<c;
      break;
      case 3:
      case 5:
      case 7:
      case 8:
      case 10:
      case 12:
      cout<<"Days of year: "<<a-1;
      break;
      case 4:
      case 6:
      case 9:
      case 11:
      cout<<"Days of year: "<<b-1;
      break;
      case 2:
      cout<<"Days of year: "<<d;
      break;
}
      return 0;
}


  • 写回答

3条回答 默认 最新

  • 心寒丶 全栈领域优质创作者 2022-10-11 12:14
    关注

    先输入再计算,赋值用一个=,不是两个

    #include <iostream>
    using namespace std;
    /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     
    int main(int argc, char** argv) {
        int year,month,day,a,b,c,d;
        a=0;
        b=0;
        c=0;
        d=0;
      
        cout<<"Input year,month,day: "<<endl;
        cin>>year>>month>>day;
        a=(month-1)*31+day+29;
        b=(month-1)*30+day+29;
        c=day;
        d=31+day;
        if(year%4==0&&year%100!=0||year%100==0)
          switch(month){
          case 1:
          cout<<"Days of year: "<<c;
          break;
          case 3:
          case 5:
          case 7:
          case 8:
          case 10:
          case 12:
          cout<<"Days of year: "<<a;
          break;
          case 4:
          case 6:
          case 9:
          case 11:
          cout<<"Days of year: "<<b;
          break;
          case 2:
          cout<<"Days of year: "<<d;
          break;
          }
          else 
              switch(month)
              {
                  case 1:
          cout<<"Days of year: "<<c;
          break;
          case 3:
          case 5:
          case 7:
          case 8:
          case 10:
          case 12:
          cout<<"Days of year: "<<a-1;
          break;
          case 4:
          case 6:
          case 9:
          case 11:
          cout<<"Days of year: "<<b-1;
          break;
          case 2:
          cout<<"Days of year: "<<d;
          break;
    }
          return 0;
    }
     
     
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 10月19日
  • 已采纳回答 10月11日
  • 创建了问题 10月11日

悬赏问题

  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误