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 #include #include using namespace std;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!