Read a 3-character string from input into variable inString. Declare a Boolean variable isValid and assign isValid with true if inString only contains digits. Otherwise, assign isValid with false. Ex: If the input is 050, then isValid is assigned with true, so the output is: Good string Ex: If the input is h61, then isValid is assigned with false, so the output is: Bad string Note: Use getline(cin, inString) to read the entire line from input into inString #include #include #include using namespace std; int main() {    string inString;        /* Your code goes here */    if (isValid) {       cout << "Good string" << endl;    }    else {       cout << "Bad string" << endl;    }    return 0; }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 19RQ
icon
Related questions
icon
Concept explainers
Question

Read a 3-character string from input into variable inString. Declare a Boolean variable isValid and assign isValid with true if inString only contains digits. Otherwise, assign isValid with false.

Ex: If the input is 050, then isValid is assigned with true, so the output is:

Good string

Ex: If the input is h61, then isValid is assigned with false, so the output is:

Bad string

Note: Use getline(cin, inString) to read the entire line from input into inString

#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main() {
   string inString;
   
   /* Your code goes here */

   if (isValid) {
      cout << "Good string" << endl;
   }
   else {
      cout << "Bad string" << endl;
   }

   return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT