Read a 2-character string from input into variable inputString. Declare a Boolean variable isValid and assign isValid with true if inputString contains a lowercase letter. Otherwise, assign isValid with false. Ex: If the input is y-, then isValid is assigned with true, so the output is: Valid string Ex: If the input is 21, then isValid is assigned with false, so the output is: Invalid string Note: Use getline(cin, inputString) to read the entire line from input into inputString. #include #include #include using namespace std; int main() {
Read a 2-character string from input into variable inputString. Declare a Boolean variable isValid and assign isValid with true if inputString contains a lowercase letter. Otherwise, assign isValid with false.
Ex: If the input is y-, then isValid is assigned with true, so the output is:
Valid string
Ex: If the input is 21, then isValid is assigned with false, so the output is:
Invalid string
Note: Use getline(cin, inputString) to read the entire line from input into inputString.
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main() {
string inputString;
/* Your code goes here */
if (isValid) {
cout << "Valid string" << endl;
}
else {
cout << "Invalid string" << endl;
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images