所以我几乎刚刚开始编码。我想知道你们中的任何人是否可以帮我解决这个简单的代码。 我需要说明在下一个闰年还有多少年,我迷失了。
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;
}
答案 0 :(得分:0)
我修改了你的代码。请使用以下代码并尝试了解您的错误: -
int main()
{
int year;
cout << "Enter a year: ";
cin >> year;
int isleap = year % 4;
if (isleap == 0)
{
isleap = year % 100;
if (isleap == 0)
{
isleap = year % 400;
if (isleap == 0)
cout << year << " is a leap year."<<endl;
else
cout << "There is " << (4-isleap) << " years till next leap year"<<endl;
}
else
cout << year << " is a leap year."<<endl;
}
else
cout << "There is " << (4-isleap) << " years till next leap year"<<endl;
return 0;
}