有人可以帮我修复这个C ++代码吗? [英] Can someone please help me fix this C++ code?
问题描述
我正在尝试对此进行编程,因此如果签名为CCC,则输出No,否则输出Yes...
我收到以下错误:
nccc5j1.cpp:在函数'int main()'中:
nccc5j1.cpp:6:9:错误:'signatureNotAllowed'之前的预期初始值设定项
signatureNotAllowed =CCC;
^ ~~~~~~~~~~~~~~~~~~
nccc5j1。 cpp:9:15:错误:'signatureNotAllowed'未在此范围内声明
If(input == signatureNotAllowed)
^ ~~~~~~~~~ ~~~~~~~~~
nccc5j1.cpp:9:34:错误:'if'未在此范围内声明
If(input == signatureNotAllowed )
^
我的尝试:
I am trying to program this, so that if the signature is "CCC" then output "No", else output "Yes"...
I get the following error:
nccc5j1.cpp: In function 'int main()':
nccc5j1.cpp:6:9: error: expected initializer before 'signatureNotAllowed'
signatureNotAllowed = "CCC";
^~~~~~~~~~~~~~~~~~~
nccc5j1.cpp:9:15: error: 'signatureNotAllowed' was not declared in this scope
If (input == signatureNotAllowed)
^~~~~~~~~~~~~~~~~~~
nccc5j1.cpp:9:34: error: 'If' was not declared in this scope
If (input == signatureNotAllowed)
^
What I have tried:
#include <iostream>
using namespace std;
int main() {
string signatureNotAllowed
signatureNotAllowed = "CCC";
string input;
cin >> input;
If (input == signatureNotAllowed)
cout <<"No"<<endl;
If (input != signatureNotAllowed)
cout << "Yes"<<endl;
return 0;
}
推荐答案
在 signatureNotAllowed $ c $的末尾添加分号c>变量声明:
Either add a semicolon at then end of thesignatureNotAllowed
variable declaration:
string signatureNotAllowed;
signatureNotAllowed = "CCC"s;
或在同一行上声明并初始化变量:
or declare and initialize the variable on the same line:
string signatureNotAllowed = "CCC"s;
您还必须使用 s
后缀字符串以初始化字符串
变量;否则你必须将它声明为 char *
。
You also have to suffix the string with s
to initialize a string
variable; otherwise you have to declare it as a char*
.
如果 c>你还错误拼写 code>,它在开始时使用了一个低于它的情况。并且你不需要第二个 if
,因为你已经测试了相等性,只需使用 else
进行后半部分,与正常演讲中的情况相同。
You have also mis-spelledif
, it uses a ower case i at the beginning. And you do not need the secondif
because you have already tested for equality, just useelse
for the second half, the same as you would in normal speech.
if (input == signatureNotAllowed)
cout <<"No"<<endl;
else
cout << "Yes"<<endl;
这篇关于有人可以帮我修复这个C ++代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!