Error, please fix | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Error, please fix

I'm trying to create a password with if and else but somehow it sin't working.... Here is my code: #include <iostream> using namespace std; int main() { string a, b ; b = "hey"; cout << "Enter password:"; cin >> a; if (string a = b) { cout << "nice!"; } else { cout << "sorry, wrong!"; } } Error message: Error (active) E0711 expression must have bool type (or be convertible to bool) Error C2451 conditional expression of type 'std::string' is illegal

3rd Aug 2020, 8:56 PM
Carl Stromo
Carl Stromo - avatar
2 Answers
0
In the if condition, you are assigning b to a and not comparing them. Remember, = is for assignment and == is for comparison. Also you don't need the `string` type specifier if the variable has been initialized before. Change = to == and remove "string" in `if (string a = b)`
3rd Aug 2020, 9:06 PM
XXX
XXX - avatar
0
Thank you!
3rd Aug 2020, 9:29 PM
Carl Stromo
Carl Stromo - avatar