VC++ 求闰年遇到的错误...

来源:百度知道 编辑:UC知道 时间:2024/06/10 23:25:46
我用VC++ 6.0判断一个年份是否为闰年程序如下:

#include <iostream>
using namespace std;
int main()
{
int year;
bool IsLeap Year;
cout<<"Enter the year:";
cin>>year;
IsLeap Year=((year%4==0 && year%100!=0)||(year%400==0));
if(IsLeap Year)
cout<<year<<"is a leap year"<<endl;
else
cout<<year<<"is not a leap year"<<endl;
}

执行编译后,屏幕显示:
2_2B.CPP
E:\My Documents\我的资料\VC++\2_2\2_2B.CPP(6) : error C2146: syntax error : missing ';' before identifier 'Year'
E:\My Documents\我的资料\VC++\2_2\2_2B.CPP(6) : error C2065: 'Year' : undeclared identifier
E:\My Documents\我的资料\VC++\2_2\2_2B.CPP(9) : error C2146: syntax error : missing ';' before identifier 'Year'
E:\My Documents\我的资料\VC++\2_2\2_2B.CPP(10) :

bool IsLeap Year;

变量名中不能出现空格

程序修改如下:

//---------------------------------------------------------------------------

#include <iostream>
using namespace std;
int main()
{
int year;
bool IsLeap_Year;
cout<<"Enter the year:";
cin>>year;
IsLeap_Year=((year%4==0 && year%100!=0)||(year%400==0));
if(IsLeap_Year)
cout<<year<<"is a leap year"<<endl;
else
cout<<year<<"is not a leap year"<<endl;
}
//---------------------------------------------------------------------------