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

if语句出现错误!

笨鸟后飞_ 发布于 2013-03-28 16:30, 387 次点击
#include <iostream>
using namespace std;
void main()
{
    int n,a,b,c,d,e;
    cout<<"整数n=";
    cin>>n;
    a=n/10000;
    b=(n-a*10000)/1000;
    c=(n-a*10000-b*1000)/100;
    d=(n-a*10000-b*1000-c*100)/10;
    e=(n-a*10000-b*1000-c*100-d*10);
    cout<<"n的逆序数为"<<e<<d<<c<<b<<a<<endl;
    if(a!=0)
        cout<<"n为5位数";
        else if(b!=0)
        cout<<"n为4位数";
        else if(c!=0)
        cout<<"n为3位数";
        else if(d!=0)
        cout<<"n为2位数";
        else if(e!=0)
        cout<<"n为1位数";
        else
        cout<<"error!"
}
2 回复
#2
yuccn2013-03-28 16:36
    if(a!=0)
         cout<<"n为5位数";// 这个地方输入了全角的;了
         else if(b!=0)
         cout<<"n为4位数";
         else if(c!=0)
         cout<<"n为3位数";
         else if(d!=0)
         cout<<"n为2位数";
         else if(e!=0)
         cout<<"n为1位数";
         else
         cout<<"error!" // 这个地方没有分号
 }
#3
笨鸟后飞_2013-03-28 16:53
噢噢,又是细节...谢谢了.
1