I want to find whether a password entered by the user is valid or invalid. For this case, a valid password is one which contains at least one uppercase letter, one lowercase letter, one number and one dollar sign ($). When I search for the dollar sign the compiler throws an error:
ISO C++ forbids comparison between pointer and integer
This is how I search for the dollar sign:
for(int i = 0; i < x.length(); i++) {
if(x[i] == "$") {
dlr = 1;
}
}
And this is the complete program:
#include <iostream>
#include <string.h>
using namespace std;
int main () {
string x("");
cin >> x;
bool upr = 0;
bool lwr = 0;
bool dlr = 0;
bool num = 0;
for(int i = 0; i < x.length(); i++) {
if(isupper(x[i])) {
upr = 1;
}
if(islower(x[i])) {
lwr = 1;
}
if(x[i] == "$") {
dlr = 1;
}
if(isdigit(x[i])) {
num = 1;
}
}
if(upr == lwr == dlr == num == 1) {
cout << "The password is valid";
} else {
cout << "The password is invalid";
}
cout << dlr;
return 0;
}