Concept explainers
Read a 2-character string from input into variable userString. Declare a Boolean variable isValid and assign isValid with true if the following conditions are met:
- userString does not contain two of the same character.
- For alphabetic characters, userString does not contain two of the same letter (regardless of case).
Otherwise, assign isValid with false.
Ex: If the input is 2-, then isValid is assigned with true, so the output is:
String accepted
Ex: If the input is Tt, then isValid is assigned with false, so the output is:
String not accepted
Note: Use getline(cin, userString) to read the entire line from input into userString.
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main() {
string userString;
/* Your code goes here */
if (isValid) {
cout << "String accepted" << endl;
}
else {
cout << "String not accepted" << endl;
}
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images
- Q1: Which is not a Python keyword for decision structures: Else if elseif elif Q2: The result of an if's logical expression can be a string. True False Q3: The statement immediately following an if statement must: use the print() function be commented be mathematical be indented Q4: At the end of an if statement you must use a comma semi-colon period colon Q5: Assuming a and b are string variables, which is a value if statement? if a==b: if a <> b: if a = b: if a equals b:arrow_forwardWrite a statement that defines a string variable called city that can hold a string of up to 20 characters.arrow_forwarda)Create a string variable and assign to it your favorite color. b) Write Matlab code that prompts the user to guess your favorite color. After the user has had 3 attempts, the program displays the message "Incorrect. You run out of chances!" and stops.arrow_forward
- Design an algorithm or function to find the longest substring which contains 2 unique characters in a given string. You may list steps or psuedo code. Example: In the string "abaacacaacda" return "aacacaac"arrow_forwardHi, I need to solve this problem with C++ programming language using Visual Studio. Thank youarrow_forwardGiven a String variable named brand that has been declared and initialized, write the statement needed to create a new integer variable named numChars that contains the number of characters in the String. int numChars =arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education