错误C2061:语法错误:标识符'finalScore' [英] error C2061: syntax error : identifier 'finalScore'

查看:109
本文介绍了错误C2061:语法错误:标识符'finalScore'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码遇到了问题。这是我的第一个C ++项目。我一直在我的标识符上得到错误,但它在代码的早期工作正常。有小费吗?谢谢你好



Hi, I am having trouble with my code. This is my first C++ project. I keep getting the error on my identifier, but it works fine earlier in the code. Any tips? Thank yo

#include <iostream>
using namespace std;


int main()
{
		int finalScore;
		cout << "Please enter your final test score  > ";
		cin >> finalScore;

		{if (finalScore >= 60)
			cout << "Congratulations you have passed";

		else if (finalScore < 60)
			cout << "You have failed.Next time try harder."; }

		system("PAUSE");
	return 0;

}

推荐答案

如果你写的是
If you write
#include <iostream>



不会有任何编译错误。如果您有一些错误,则无法与此标识符相关联。检查 #include 行中的内容。我只是解释:你的观察是不正确的。干净地重建项目。



解决方案1错误,但建议是正确的:您不需要这些额外的括号。

另外,如果(finalScore< 60),用 else 替换 else。我甚至要解释原因吗?另外,避免立即常量如60,而是声明显式常量,否则你的代码将不适合维护。



- SA


there won't be any compilation errors. If you have some errors, they cannot be related with this identifier. Check up what's in the #include line. I have only on explanation: your observation is incorrect. Rebuild the project cleanly.

Solution 1 is wrong, but the advice is correct: you don't need these extra brackets.
Also, replace else if (finalScore < 60) with else. Do I even have to explain why? Also, avoid immediate constants like 60, instead, declare explicit constant, otherwise your code would be bad for maintenance.

—SA


我尝试删除花括号,但它不会改变任何东西。似乎它没有读取变量finalScore,但我不确定为什么。我已经按照我的书中的格式示例,尝试使用Google搜索,但仍然丢失了。任何帮助将不胜感激。
I tried removing the curly braces, but it does not change anything. It seems like it is not reading the variable finalScore, but I am not sure why. I have followed the format example from my book, and have tried googling this, but am still lost. Any help would be appreciated.


这篇关于错误C2061:语法错误:标识符'finalScore'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆