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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started