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 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的