//题目:输入一个年份,判断是否有闰年.
#include<iostream>
using namespace std;
int main()
{
int year;
bool IsLeapYear;
cout<<"Enter the year:/n"; //提醒用户输入
cout<<"if enter 0,exit the program./n";
cin>>year;
while (year)
{
IsLeapYear =((year % 4 == 0&& year % 100!=0)||(year%400==0));
if(IsLeapYear)
cout<<year<<"is a leap year/n/n/n"<<endl;
else
cout<<year<<"is not a leap year/n/n/n"<<endl;
cout<<"If you want to continue,please Enter the year:/n"; //请求用户再次输入
cout<<"if enter 0,esit the program./n";
cin>>year;
}
}
//此程序有一个问题:对于错误输入字母会造成死循环,如何解决?
//题目:输入一个年份,判断是否有闰年. 碰到一个问题```
本文介绍了一个简单的C++程序,用于判断用户输入的年份是否为闰年。程序使用了基本的条件判断逻辑,并通过循环允许用户多次输入直到选择退出。

被折叠的 条评论
为什么被折叠?



