「已注销」 2018-10-14 01:38 采纳率: 33.3%
浏览 2484
已结题

case语句中case的用法

要求:输入5+, 输出100;输入5-,输出90;输入5,输出95。
我的写法如下,输出5的时候必须加一个空格,如何去掉空格呢?请问该如何编写呢?

``` case 5:
switch(b) {
case '+':
printf("The score is 100.\n");
break;
case '-':
printf("The score is 85.\n");
break;
case '0':
printf("The score is 90.\n");
break;
default:
printf("False input.\n");
}
break;

  • 写回答

2条回答

  • 「已注销」 2018-10-14 02:08
    关注

    #include
    int main(int argc, char *argv[])
    {
    int a;
    char b;
    scanf("%d%c",&a,&b); //ab两个输入连续输入到操作台,中间没有符号隔开
    switch(a){
    case 5:
    switch(b) { //先判定a,再判定b,switch的嵌套
    case '+':
    printf("The score is 100.\n");
    break;
    case '-':
    printf("The score is 85.\n");
    break;
    case ' ':
    printf("The score is 90.\n"); //如果输入的只有5,被判定为错误的输入,所以此处我编写的程序需输入“5”加上“空格”
    // 请问老师:如果要实现只输入5,运行就能输出90. case后该如何写?就是声明case后为空。
    break;
    default:
    printf("False input.\n");
    }
    break;
    case 4:
    switch(b) {
    case '+':
    printf("The score is 80.\n");
    break;
    case '-':
    printf("The score is 70.\n");
    break;
    case ' ':
    printf("The score is 75.\n");
    break;
    default:
    printf("False input.\n");
    }
    break;
    case 3:
    printf("The score is 60.\n");
    break;
    case 2:
    printf("The score is <60.\n");
    break;
    case 1:
    printf("The score is < 60.\n");
    break;
    default:
    printf("False input!\n");
    }

    return 0;
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?