【发布时间】:2017-11-27 01:34:35
【问题描述】:
所以我几乎刚刚开始编码。我想知道你们中是否有人可以帮助我编写这个简单的代码。 我需要说明距离下一个闰年还有多少年,我迷路了。
int main()
{
int year;
cout << "Enter a year: ";
cin >> year;
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
cout << year << " is a leap year.";
else
cout << "There is " << 4%-year << " years till next leap year";
}
else
cout << year << " is a leap year.";
}
else
cout << "There is " << ???year << " years till next leap year";
return 0;
}
【问题讨论】:
-
顺便说一句,如果语法正确,表达式
4%-year等于4 % (-year)。我认为这不是你想要的。 -
您好,欢迎来到 StackOverflow。请花一些时间阅读帮助页面,尤其是名为"What topics can I ask about here?" 和"What types of questions should I avoid asking?" 的部分。更重要的是,请阅读the Stack Overflow question checklist。您可能还想了解Minimal, Complete, and Verifiable Examples。
-
如果你有
bool IsLeapYear(int year)函数,那么你可以做if (!IsLeapYear(year)) { int nextLeapYear = year; while(!IsLeapYear(nextLeapYear)) nextLeapYear++; cout << "There is " << (nextLeapYear - year) << " years till next leap year"; }