预期在 if 和 else 语句上的语句上出错
Error on expected a statement on if and else statement
在我的比较问题中,我使用了if和else语句,所以我得到了一个错误。
这是我的代码:
#include <iostream>
using namespace std;
int main() {
double lgt, hgt, lgt1, hgt1, x, y;
cout << "enter the length of retangle 1= ";
cin >> lgt;
cout << "Enter the height of rectangle 1= ";
cin >> hgt;
cout << "enter the length of rectangle 2= ";
cin >> lgt1;
cout << "enter the height of rectangle 2= ";
cin >> hgt1;
x = lgt*hgt;
y = lgt1*hgt1;
if (x == y); {
cout << "both is same" << endl;
}
else if (x > y);{
cout << "rectangle 1 is bigger" << endl;
}
else {
cout << "rectangle 2 is bigger" << endl;
}
return 0;
}
是什么原因导致此错误发生?
你在第一个 else 条件下有一个错误的分号 ( ;
)。 代码应更改为:
else if (x > y) {
在分支语句中的布尔表达式后使用分号在语法上是不正确的。分号表示语句的结尾,因此,语句必须有效才能关闭它。
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- 我的简单if-else语句是如何无法访问的代码
- 有一个打印语句的函数是一种糟糕的编程实践吗
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- 为什么是0;C++中的有效语句
- C++ 使用 OpenMP 时,如果 for 循环在 if else 语句中出错
- R6010 执行后出错.if 语句在 for 循环中.[作业][中止已解决,发现新问题]
- 关闭文件流时出错,其存在取决于与 C++ 中的 .close() 语句相同的布尔值
- 预期在 if 和 else 语句上的语句上出错
- c++中克隆系统调用语句出错
- 在IF语句中添加时出错
- 编写 if 语句时出错"'=' : left operand must be l-value"
- 我的代码中的switch语句出错.(c++)
- 使用 if 语句时出错