它通常工作,但在4,6,9和11个月的任何特定日期,它只是跳到下一个月的第一天。
#include <iostream>
using namespace std;
int main()
{
cout << "What is the day after the date you enter?:";
int day, month, year;
cin >> day >> month >> year;
if (day == 31 && month == 12)
{
day = 1;
month = 1;
year = year + 1;
}
else if (day == 31 && month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10)
{
day = 1;
month = month + 1;
}
else if (day == 30 && month == 4 || month == 6 || month == 9 || month == 11)
{
day = 1;
month = month + 1;
}
else if (day == 28 && month == 2)
{
day = 1;
month = month + 1;
}
else if (day == 29 && month == 2)
{
day = 1;
month = month + 1;
}
else
{
day = day + 1;
}
cout << "The day after the date you entered is: " << day << "/" << month << "/" << year << endl;
return 0;
system("pause");
}
`
例如,我使用的第一个日期是14 09 2020,它输出1/10/2020
this is a picture for proof
Idk怎么办,请帮助
1条答案
按热度按时间k7fdbhmy1#
你需要更多的支架
应该是
在下一个
else if
上也出现相同的错误。&&
的优先级高于||
,因此您需要使用方括号来解决此问题。