C++中的"Expected a statement"是什么意思
What does it mean mean by "Expected a statement" in C++
我已经在Visual Studio中输入了C 中的IF代码,它表明,如果
我的代码是
#include <iostream>
using namespace std;
int main()
{
float marks, result;
cout << "Enter your Marks:";
cin >> marks;
if(marks>=50 && marks <= 100);
{
cout << "Passed";
}
else if (marks < 50 && marks>=0);
{
cout << "The grade is F ";
}
else
{
cout << "Enter marks correctly";
}
}
output is
Enter your marks:97
passedenter marks correctly
if和否则都打印出两个语句
问题是这里
if(marks>=50 && marks <= 100);
您有不应该在那里的;
。因此,;
是if
语句的主体。这意味着"什么都不做"。结果,以下
{
cout << "Passed";
}
...与if
语句无关,将始终执行。之后就是这样:
else if (marks < 50 && marks>=0);
相同的问题,但是else
无法编译,因为之前没有if
。请记住,else
之前的块错误不是if
的一部分。相反,您想要的是:
if(marks>=50 && marks <= 100)
{
cout << "Passed";
}
else if (marks < 50 && marks>=0)
{
cout << "The grade is F ";
}
else
{
cout << "Enter marks correctly";
}
相关文章:
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 标准 N3337 5.2.10 第 7 条中的C++"类型"是什么意思?
- "类模板示例<int>;"语句对 C++11 是什么意思?
- 线应该是什么意思
- "CID"在AT+HTTPPARA= "CID" ,1中是什么意思
- 表达式"b=(b-x)&x"是什么意思?
- 这个表达是什么意思?
- 此代码验证公式是什么意思?
- 跟踪日志中的T.11803()是什么意思?
- 这个额外的关键字在这个 c++ 类声明中是什么意思?
- * 和 ** 在 C++ 函数声明中是什么意思?
- _T("xyz")是什么意思?
- #define Dbg(fmt,..) (0) 是什么意思? 警告:表达式无效
- 这行代码到底是什么意思?
- 在命名空间名称之前加上 :: 是什么意思?
- 从字符数组的元素中减去'a'是什么意思
- "friend"关键字在C++中是什么意思?
- 减法中的"0"是什么意思?
- 字符数组前面的加号是什么意思?
- 这里的字符串函数是什么意思