- C++中 if条件 的执行语句超过一句时 需要加上{} 否则会报错'else' without a previous '
附上C++判断闰年的代码
#include<iostream>
using namespace std;
int main()
{
int year;
bool a;
cout<<"请输入年份";
cin>>year;
if (((year%4==0)&&(year%100)!=0)||(year%400==0))
{
a=true;
cout<<year<<"是闰年";}
else
{
a=false;
cout<<year<<"不是闰年";}
return 0;
}