c++怎么错了,
using namespace std;
int main()
{
short int a,d;
cout<<"请输入出生年。"<<endl;
cin>>a;
d=a%12;
cout<<d;
else if(d==4)
cout<<"鼠"<<endl
else if(d==5)
cout<<"牛"<<endl
else if(d==6)
cout<<"虎"<<endl
else if(d==7)
cout<<"兔"<<endl
else if(d==8)
cout<<"龙"<<endl
else if(d==9)
cout<<"蛇"<<endl
else if(d==10)
cout<<"马"<<endl
else if(d==11)
cout<<"羊"<<endl
else if(d==0)
cout<<"猴"<<endl
else if(d==1)
cout<<"鸡"<<endl
else if(d==2)
cout<<"狗"<<endl
else if(d==3)
cout<<"猪"<<endl
system("pause")
cout<<(char)(65+18)<<(char)(65+1)<<13;
return 0;
} 展开
看控制台倒数第二第三行的提示,意哪闷思为“在else之前没有if”,“else之前的语句没有‘;’”。根据这个可以作出相应更改。更改之后的代码如下:
(每条语句后面要加“;”,另外使用system()要李激弯包含stdlib.h)
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
short int a,d;
cout<<"请输入出生年。"<<endl;
cin>>a;
d=a%12;
cout<<d;
if(d==4)
cout<<"鼠"<<endl ;
else if(d==5)
cout<<"牛"<<endl ;
铅宴 else if(d==6)
cout<<"虎"<<endl ;
else if(d==7)
cout<<"兔"<<endl ;
else if(d==8)
cout<<"龙"<<endl ;
else if(d==9)
cout<<"蛇"<<endl ;
else if(d==10)
cout<<"马"<<endl ;
else if(d==11)
cout<<"羊"<<endl ;
else if(d==0)
cout<<"猴"<<endl ;
else if(d==1)
cout<<"鸡"<<endl ;
else if(d==2)
cout<<"狗"<<endl ;
else if(d==3)
cout<<"猪"<<endl ;
system("pause");
cout<<(char)(65+18)<<(char)(65+1)<<13;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
short int a,d;
cout<<"请输入出生年。"<<endl;
桥穗 cin>>a;
d=a%12;
cout<<d;
if(d==4)//先有if才能后else if
cout<<"鼠"<<endl; //要有; 下面的也一样
else if(d==5)
cout<<"牛"<<endl;
else if(d==6)
cout<<"虎"<<endl;
else if(d==7)
cout<<"兔"<<穗皮endl;
else if(d==8)
cout<<"龙"<<endl;
else if(d==9)
cout<<"蛇"<<endl;
else if(d==10)
cout<<"马"<<endl;
else if(d==11)
cout<<"羊"<<endl;
else if(d==0)
cout<<"猴"<<endl;
else if(d==1)
cout<<"鸡"<<endl;
else if(d==2)
cout<<"狗"<<敏族卜endl;
else if(d==3)
cout<<"猪"<<endl;
system("pause");
cout<<(char)(65+18)<<(char)(65+1)<<13;
return 0;
}
输出对不对我就不知道了 还有问题可以追问
我用不了,
请把你改完后的c++代码发给我
上面的代码已经改了可以用了啊
else if(){}
else(){}
你衫散没有if语句野谨是不行的,else if或颂塌基else语句要和if配套使用哦
cout<<d;
else if(d==4)
cout<<丛者陵"鼠"<<endl
你的嫌兄else前面没有if,当然会错渗戚;
还有,建议你用switch函数(多分枝选择函数)。
把第一个else if{}改为if{}
using namespace std;
int main()
{
short int a,d;
cout<<"请输入出生年。磨慎"<<endl;
cin>>a;
d=a%12;
cout<<d;
if(d==4)
cout<<"鼠"<<endl;
else if(d==5)
cout<<"牛"<<endl;
else if(d==6)
cout<<"虎"<<endl;
else if(d==7)
cout<<"兔"<<endl;
else if(d==8)
cout<<"龙"<<endl;
else if(d==9)
cout<<"蛇"<宽游链<endl;
else if(d==10)
cout<<"马"<<endl;
else if(d==11)
cout<<"羊"<<endl;
else if(d==0)
cout<<"猴"<<endl;
else if(d==1)
cout<<慎孙"鸡"<<endl;
else if(d==2)
cout<<"狗"<<endl;
else if(d==3)
cout<<"猪"<<endl;
system("pause");
cout<<(char)(65+18)<<(char)(65+1)<<13;
return 0;
}