闰年锻炼。但是"else"必须打印到下一个闰年还剩多少年
Leap year exercise. but "else" has to print how many years there is left to next leap year
,所以我几乎刚刚开始编码。我想知道你们中的任何一个都可以帮助我使用这个简单的代码。我需要说明直到下一个leap年还剩多少年,我迷路了。
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;
}
我修改了您的代码。请使用以下代码进行相同的代码,并尝试了解您的错误: -
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;
}
相关文章:
- 重新定位图像时如何前进到下一个内存块
- 为什么C++对链表中的下一个节点使用指针,而像 C# 或 Java 这样的语言只使用类 Node 的名称?
- 用于在 C++ 中使用 while 循环查找下一个素数的简单函数
- CIN 仅在输入非数字值时跳过下一个 CIN
- 查找最小的下一个更大的元素
- 转到基于范围的 for 循环中的下一个迭代器
- 如何检查流中文件的下一个单词是否为 alpha?
- 如何打印下一个字母直到 Z 并继续到 A?
- 在使用堆栈为下一个最大数字编写代码时面临 SIGSEGV(分段错误)
- 使用一个内存集数组和单个堆栈在 O(n) 中查找数组的下一个更大元素
- 有没有一种标准方法可以在C++中获取第 n 个"下一个"浮点值
- 下一个云桌面客户端构建过程
- C++自定义流操纵器,用于更改流上的下一个字符串
- 链表指针赋值为什么我们不能直接将尾巴分配给 temp 而不是尾巴>尾巴下一个
- 下一个排列定义
- 查找下一个具有真值C++的数组索引
- 如何比较文件中包含的下一个字符
- 检查IP是否在其他IP网络范围内,并查找下一个可用IP
- 当我使用c++生成器时,如何在输入完成后自动跳转到下一个"TEdit"
- 闰年锻炼。但是"else"必须打印到下一个闰年还剩多少年