5条回答 默认 最新
- benbenli 2021-05-10 05:33关注
你的变量 a 是定义在同一scope,但是你定义了2次,编译器好像还每理解你的意图 (可能因为加了括号的缘故),所以它说还每定义。这样写吧,运行通过了。其实还要加上输入错误检测,年份范围,月份1-12, 天也要在每月天数范围等。
#include <iostream> using namespace std; int main() { int month_days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int leap_month_days[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; cout << "please enter year, month and day, and press ENTER:"; int y, m, d; cin >> y >> m >> d; int* md = (y % 4 == 8 && y % 100 != 0 || y % 400 == 0) ? leap_month_days : month_days; int s = d; for (int i = 0; i < m - 1; ++i) { s += md[i]; } cout << "It's the " << s << "th day in the year." << endl; return 0; } // Output please enter year, month and day, and press ENTER:2021 5 9 It's the 129th day in the year. please enter year, month and day, and press ENTER:2021 01 30 It's the 30th day in the year. please enter year, month and day, and press ENTER:2020 3 1 It's the 60th day in the year.
如果你满意我的回答,请点采纳,我很感谢你的认可。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用 1
悬赏问题
- ¥15 ETLCloud 处理json多层级问题
- ¥15 matlab中使用gurobi时报错
- ¥15 这个主板怎么能扩出一两个sata口
- ¥15 不是,这到底错哪儿了😭
- ¥15 2020长安杯与连接网探
- ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
- ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
- ¥15 可见光定位matlab仿真
- ¥15 arduino 四自由度机械臂
- ¥15 wordpress 产品图片 GIF 没法显示