Question: Read in a 2-character string from input into variable userCode. Declare a boolean variable isValid and set isValid to true if the following conditions are
Read in a 2-character string from input into variable userCode. Declare a boolean variable isValid and set isValid to true if the following conditions are met:
userCode does not contain two of the same character.
For alphabetic characters, userCode does not contain two of the same letter (regardless of case).
Otherwise, set isValid to false.
Ex: If the input is k#, then isValid is assigned with true, so the output is:
Passcode accepted
Ex: If the input is Jj, then isValid is assigned with false, so the output is:
Passcode not accepted
Note: Use getline(cin, userCode) to read the entire line from input into userCode.
#include
int main() { string userCode; if (isValid) { cout << "Passcode accepted" << endl; } else { cout << "Passcode not accepted" << endl; }
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
