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
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)`
0
Thank you!