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

求教一下哪里错了,看不出来,初学者谢谢

低调的男人 发布于 2015-10-25 15:23, 474 次点击
#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
    int x;
    cin>>x;
    x=x/10;
    if(x>=0&&x<5,x=5)
    switch(x)
    {
        case 10;
    case 9;cout<<"A"<<endl;break;
        case 8;
            case 7;cout<<"B"<<endl;break;
            case 6;cout<<"C"<<endl;break;
                case 5;cout<<"D"<<endl;break;}
    else
    {cout<<"输入错误"<<endl;}
}
1>  gjnfg.cpp
1>c:\users\administrator\documents\visual studio 2010\projects\gjnfg\gjnfg\gjnfg.cpp(14): error C2143: 语法错误 : 缺少“:”(在“;”的前面)
1>c:\users\administrator\documents\visual studio 2010\projects\gjnfg\gjnfg\gjnfg.cpp(15): error C2143: 语法错误 : 缺少“:”(在“;”的前面)
1>c:\users\administrator\documents\visual studio 2010\projects\gjnfg\gjnfg\gjnfg.cpp(16): error C2143: 语法错误 : 缺少“:”(在“;”的前面)
1>c:\users\administrator\documents\visual studio 2010\projects\gjnfg\gjnfg\gjnfg.cpp(17): error C2143: 语法错误 : 缺少“:”(在“;”的前面)
1>c:\users\administrator\documents\visual studio 2010\projects\gjnfg\gjnfg\gjnfg.cpp(18): error C2143: 语法错误 : 缺少“:”(在“;”的前面)
1>c:\users\administrator\documents\visual studio 2010\projects\gjnfg\gjnfg\gjnfg.cpp(19): error C2143: 语法错误 : 缺少“:”(在“;”的前面)
4 回复
#2
rjsp2015-10-25 15:46
case 10; 这里后面应该是冒号,不是分号。下同
#3
孤狼A组2015-10-25 20:03
看你的意思,我感觉你应该是要这样的
//#include "stdafx.h"
 #include<iostream>
 using namespace std;
 int main()
 {
     int x;
     cin>>x;
     x=x/10;
     if(x>=5 && x<10)
     switch(x)
     {
         case 10:
         case 9:cout<<"A"<<endl;break;
         case 8:
         case 7:cout<<"B"<<endl;break;
         case 6:cout<<"C"<<endl;break;
         case 5:cout<<"D"<<endl;break;}
     else
     {cout<<"&Ecirc;&auml;&Egrave;&euml;&acute;í&Icirc;ó"<<endl;}
 }  
按你那样,总是输出D
#4
U2010100092015-10-26 09:47
if判断逻辑错误,更改为:
if(x >= 0 && x <= 5)
    x = 5;
#5
我是XXX2016-07-18 16:19
case X(数字)后面要跟:不是;
1