CHALLENGE ACTIVITY
3.15.1: Character operations.
Read in a 2-character string from input into variable userPassword. Declare a boolean variable noDuplicates and set noDuplicates to true if the following conditions are met:
• userPassword does not contain two of the same character.
• For alphabetic characters, userPassword does not contain two of the same letter (regardless of case).
Otherwise, set noDuplicates to false.
Ex: If the input is 1, then noDuplicates is assigned with true, so the output is:
Password accepted
Ex: If the input is Kk, then noDuplicates is assigned with false, so the output is:
Password not accepted
Note: Use getline(cin, userPassword) to read the entire line from input into userPassword.
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main() {
string userPassword;
/* Your code goes here */
if (noDuplicates) {
cout << "Password accepted" << endl;
}
else {
cout << "Password not accepted" << endl;
}
}