Click here to Skip to main content
15,902,636 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C++
#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;
}
Posted
Updated 12-Feb-18 23:49pm
v2

Either add a semicolon at then end of the signatureNotAllowed variable declaration:
C++
string signatureNotAllowed;
signatureNotAllowed = "CCC"s;

or declare and initialize the variable on the same line:
C++
string signatureNotAllowed = "CCC"s;

You also have to suffix the string with s to initialize a string variable; otherwise you have to declare it as a char*.
 
Share this answer
 
v3
Comments
RV2020 13-Feb-18 5:30am    
I corrected it to:
#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;
}



But there is still an error message:
nccc5j1.cpp: In function 'int main()':
nccc5j1.cpp:11:34: error: 'If' was not declared in this scope
If (input != signatureNotAllowed)


-Thanks for your help by the way!
phil.o 13-Feb-18 5:36am    
C++ is case sensitive, so if is a language statement, whereas If is unknown (and then considered as an undeclared variable).
CPallini 13-Feb-18 5:49am    
5.
phil.o 13-Feb-18 6:19am    
Thanks :)
You have also mis-spelled if, it uses a ower case i at the beginning. And you do not need the second if because you have already tested for equality, just use else for the second half, the same as you would in normal speech.
C++
if (input == signatureNotAllowed) 
    cout <<"No"<<endl;
else 
    cout << "Yes"<<endl;
 
Share this answer
 
Comments
CPallini 13-Feb-18 5:49am    
5.
RV2020 13-Feb-18 5:53am    
thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900