error C2181: illegal else without matching if
2012-09-14 20:39
295 查看
问题代码:
编译后结果:
翻译错误提示:else没有匹配的if,即else没有if与之相呼应。
修改后代码:
对比两个代码会发现问题所在了。
#include <stdio.h> void main() { int score; printf("请输入成绩(0-100):"); scanf("%d",&score); if(score<0) printf("输入数据错误\n"); else if(score<60) putchar('E'); putchar('\n'); else if(score<70) printf("D\n"); else if(score<80) printf("C\n"); else if(score<90) printf("B\n"); else if(score <= 100) printf("A\n"); else printf("输入数据错误\n"); }
编译后结果:
翻译错误提示:else没有匹配的if,即else没有if与之相呼应。
修改后代码:
#include <stdio.h> void main() { int score; printf("请输入成绩(0-100):"); scanf("%d",&score); if(score<0) printf("输入数据错误\n"); else if(score<60) { putchar('E'); putchar('\n'); } else if(score<70) printf("D\n"); else if(score<80) printf("C\n"); else if(score<90) printf("B\n"); else if(score <= 100) printf("A\n"); else printf("输入数据错误\n"); }
对比两个代码会发现问题所在了。
相关文章推荐
- error C2181: illegal else without matching if
- Compute the maximum of two integers without if-else
- 错误 3 error C2181: 没有匹配 if 的非法 else c:\users\zhong\desktop\我的程序\c++qt程序\test\sineware\sineware\sinewa
- Compare two numbers Without if-else and comparison
- if else
- 拒绝一切繁琐的if...else...
- case结构的可读性要好于if else
- Java流程控制语句——if-else语句
- c标签 if else c标签 总结
- Shell if elif else Code Example
- switch和if-else相比
- 被if-else挫了
- C#语句 分支语句 if --- else ---
- 不用if else 等判断语句判断两个数值的大小
- 2-2-2 判断语句-嵌套if-else(从2个数比较到3个数)
- 计算1-n的和(不用for, while, goto, if, else, switch, case和三目运算符, 也不用乘除法)---利用间接递归
- ActionScript 3.0 Step By Step系列(三):学学流程控制,编编if-else & switch & while & for
- oracle if else elsif 使用例子
- Java基础知识02-流程控制if-else
- 用位运算实现求绝对值-有效避开if-else判断