注册 登录
编程论坛 C++教室

请问如何将循环程序加到闰年判定程序中呢

zz109808 发布于 2013-10-19 08:39, 635 次点击
#include <stdio.h>
intmain()
{
int year,leap;
if(year%4=0)
{if( year%100=0)
if (year%400=0)
leap=1;
else
leap=0;


else
leap=1;
}
else
leap=0;
if(leap=1)
print("is ",year);
else
print("is not",year);
print("a leap year\n");
return 0;
}
10 回复
#2
xiaodu0002013-10-19 09:17
哥们是你学C++的吗?你用的好像不是标准的c++。
如果是判断闰年的话,不能用判断语句吧。如果是只是输出闰年的话,可以用循环语句。
--------讲的不好,新手批判,大神指点!!
#3
qunxingw2013-10-19 11:38
可以用,只是层次要清晰,注意缩进,适当加大括弧。
不过都没看到有数据输入语句。
#4
toofunny2013-10-20 00:43
以下是引用xiaodu000在2013-10-19 09:17:52的发言:

哥们是你学C++的吗?你用的好像不是标准的c++。
如果是判断闰年的话,不能用判断语句吧。如果是只是输出闰年的话,可以用循环语句。
--------讲的不好,新手批判,大神指点!!
表示指点:那哥们用的是c语言
#5
dengdaidw2013-10-20 00:59
#include<iostream>
using namespace std;
int main()
{
    int year;
    while(year)
    {
    cout<<"输入你要判断的年份:"<<endl;
    cin>>year;
    if((year%400==0)||(year%4==0&&year%100!=0))
        cout<<"改年是闰年"<<endl;
    else
        cout<<"改年是平年"<<endl;
    }
    return 0;
}
#6
苑天尤2013-10-20 16:42
哥们,我咋感觉楼上错了呢
#include<iostream>
 using std::cout;
using std::endl;
 int main()
 {
     while(1)
     {
         int year;
         cout<<"输入你要判断的年份:"<<endl;
         cin>>year;
         if((year%400==0)||(year%4==0&&year%100!=0))
        {
          cout<<"改年是闰年"<<endl;
          break:
         }
       else
      {
         cout<<"改年是平年"<<endl;
           break;
       }
     }
     return 0;
 }
#7
toofunny2013-10-20 17:17
以下是引用苑天尤在2013-10-20 16:42:48的发言:

哥们,我咋感觉楼上错了呢
#include
 using std::cout;
using std::endl;
 int main()
 {
     while(1)
     {
         int year;
         cout<<"输入你要判断的年份:"<
哥们,你也没写对。漏了句 using std::cin;
cout<<"输入你要判断的年份:"<         cin>>year;
改为cout<<"输入你要判断的年份:";
        cin>>year;
"改年"表示错别字

#8
dengdaidw2013-10-20 17:32
错还是没错,要运行了才知道,
#9
toofunny2013-10-21 01:28
回复 8楼 dengdaidw
咔咔,指出你错误都还不知道。你的year没有初始化,明显错误了。
#10
xiaodu0002013-10-31 09:19
回复 4楼 toofunny
你跑错地方了,这时c++专区
#11
xiaodu0002013-10-31 09:21
#include<iostream>
#include<windows.h>
using namespace std;
int main ()
{
    int a;
    system("mode con:cols=100 lines=1000") ;
    for(a=2000;a<=2500;a++)
    {
        if((a%4==0&&a%100!=0)||a%400==0)
        cout<<a<<"年是闰年"<<endl;
        else  cout<<a<<"年不是闰年"<<endl;
        
    }
    return 0;
}  
控制台只显示300行的问题完美解决
1