错误:"否则"之前应为非限定 ID
error: expected unqualified-id before 'else'
我已经尝试检查其他答案,但仍然找不到答案。我收到此错误:
compilation info
prog.cpp:192:2: error: expected unqualified-id before 'else'
else if (userInput == 3)
^
下面是代码行:
else if (userInputSolveFor == "t")
{
cout << "You are solving for time." << endl;
cout << endl;
cout << "What is the acceleration (in m/s/s)?" << endl;
cin >> acceleration;
cout << "What is the initial velocity?" << endl;
cin >> initialVelocity;
cout << "What is the distance (in meters)?" << endl;
cin >> deltaDistance;
if (initialVelocity == 0)
{
cout << "The time is " << sqrt(deltaDistance - (0.5 * acceleration)) << setprecision(10) << " seconds." << endl;
}
else if (acceleration == 0)
{
cout << "The time is " << (deltaDistance / initialVelocity) << setprecision(10) << " seconds." << endl;
}
else
{
cout << "The input you have entered is not valid." << endl;
}
}
}
else
{
cout << "The input you have entered is not valid." << endl;
}
}
else if (userInput == 3)
{
cout << "You are using vf^2 = vi^2 + 2(a)(x)." << endl;
cout << endl;
cout << "What are you trying to solve for?" <<endl;
cout << endl;
cout << "Use vf for final velocity (in m/s)." << endl;
cout << "Use vi for initial velocity (in m/s)." << endl;
cout << "Use a for acceleration." << endl;
cout << "Use x for distance (in meters)." <<endl;
cin >> userInputSolveFor;
cout << endl;
其中 192 行是
else if (userInput == 3)
我不知道该怎么办。我尝试添加/删除"}",当我更改单个大括号时出现 15+ 错误,所以我认为这不是问题所在。
从这部分代码来看,您似乎有太多的右括号,请重新格式化代码并再次检查。
编辑:或者左括号太少,无论如何,就像在第一个答案中一样,正确的格式将对您有所帮助。
你的第二个 else 语句,不属于那里。 把它剪下来,在else if(userInput==3)块之后输入。
我已经解决了这个问题...我有一个太多的括号,我缺少一个括号。谢谢大家的帮助,我对编码还很陌生,非常感谢所有的帮助。到目前为止,我正在使用Notepad++,并试图在它成为坏习惯之前学习正确的缩进。再次感谢大家。详细答案:
}
else if (userInput == 3)
} 不是必需的,太多了
并且在另一行代码中还缺少括号,这导致了 10+ 错误。再次感谢!
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- 从函数角度看ID到文件路径的内部与外部映射
- 通过组合不同的类型来创建唯一的id
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- FFMPEG配置文件级别id大小无效
- 方法内部但循环仍得到预期的不合格id错误C++
- 如何获取 GLFW 窗口 ID?
- 当简单捕获中的标识符显示为参数的声明符 ID 时,没有编译器诊断
- 当我从下面的代码中删除关键字 virtual 时,它可以正常工作,否则会出现错误。在这里"virtual"字的意义是什么?
- 显示数组中的学生 ID 和最高分
- C++:"("令牌"之前有预期的非限定 id 指向类中成员函数的指针
- 在PostgreSQL中根据它们的ID选择大量行的最快方法是什么?
- Xcode 9.4.1 中的 Apple Mach-O 链接器 (id) 错误
- 从不同目录执行时"symbol lookup error:",否则从构建目录执行时按预期工作
- 除非重新绘制大小,否则SDL_Texture在调整大小后呈现黑色
- 错误:令牌 { '{' 之前应存在非限定 ID
- 断言"id < 0"在Qt ActiveX中失败
- 为什么除非我使用 cout,否则我的值不正确?
- 错误:"否则"之前应为非限定 ID