i keep getting errors i dont understand

My code is the following:

#include <iostream>
#include <string>

{
string password;
string correctpassword="Billy";
cout<<"Please enter password."<<endl;
cin>>password;
if (password=correctpassword)

}

else

{
cout<<"Sorry,incorrect password"<<endl;
}



i keep getting these errors:||=== Build: Debug in Password (compiler: GNU GCC Compiler) ===|
D:\My Documents\Password\main.cpp|6|warning: character constant too long for its type [enabled by default]|
D:\My Documents\Password\main.cpp|4|error: expected unqualified-id before '{' token|
D:\My Documents\Password\main.cpp|13|error: expected unqualified-id before 'else'|
||=== Build failed: 2 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|


i have tried to debug this program, but i am very new to c++ so i do not know exactly where to look. I am wondering if anyone would be able to help me find the errors and how to correct them in the future. Thanksv
Hey and welcome. Please use code tags for all your code - http://www.cplusplus.com/articles/jEywvCM9/

if (password=correctpassword)
= is an assignment operator. You want the equal to operator, which is ==.

if (password == correctpassword)
Thanks Tarik, i was not aware of that. I implemented the code tags and i am now getting only one error and that is :

D:\My Documents\Password\main.cpp|14|error: expected unqualified-id before 'else'|

Im dont even know what the error ^ means... Could it be referring to the correctpassword variable?
Last edited on
Oh yea I see the problem now, your if statement is missing it's opening bracket.

1
2
3
4
if (password=correctpassword)
{ // You don't have one of those

}
SO, are you saying need to put { before my if statement like { if (password == correct password) }
Last edited on
What? Look at the piece of code I gave you, does it look like it is before the if statement? It's clearly after.
Okay i see what you are saying. This is now the code that i have...

#include <iostream>
#include <string>
using namespace std;
int main()
{
string password;
string correctpassword="Billy";
cout<<"Please enter password."<<endl;
cin>>password;

if (password == correctpassword);
{

}

else

{
cout<<"Sorry,incorrect password"<<endl;
}

Im now getting these errors, im sorry the run around, like i stated previously im very new the c++

||=== Build: Debug in Password (compiler: GNU GCC Compiler) ===|
D:\My Documents\Password\main.cpp||In function 'int main()':|
D:\My Documents\Password\main.cpp|16|error: 'else' without a previous 'if'|
D:\My Documents\Password\main.cpp|20|error: expected '}' at end of input|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
I'll respond as soon as you edit your post and use code tags like I told you to.
Your code still doesn't look like TarikNeaj's.
You have an extra semicolon.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string password;
string correctpassword="Billy";
cout<<"Please enter password."<<endl;
cin>>password;

if (password == correctpassword)
{

}

else

{
cout<<"Sorry,incorrect password"<<endl;
}
Last edited on
i have now figured my problem, thanks for helping.
Topic archived. No new replies allowed.