Read a 3-character string from input into variable inputString. Declare a Boolean variable isValid and assign isValid with true if inputString only contains alphabetic characters. Otherwise, assign isValid with false. Ex: If the input is hgr, then isValid is assigned with true, so the output is: Valid string Ex: If the input is 3rx, 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. In C++ please. #include #include #include using namespace std; int main() { string inputString; /* Your code goes here */ if (isValid) { cout << "Valid string" << endl; } else { cout << "Invalid string" << endl; } return 0; }
Read a 3-character string from input into variable inputString. Declare a Boolean variable isValid and assign isValid with true if inputString only contains alphabetic characters. Otherwise, assign isValid with false.
Ex: If the input is hgr, then isValid is assigned with true, so the output is:
Valid string
Ex: If the input is 3rx, 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 3 steps