C++ 10.17 Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs Yes if every character is a digit 0-9. Ex: If the input is: 1995 the output is: Yes Ex: If the input is: 42,000 or 1995! the output is: No Hint: Use a loop and the isdigit() function (don't forget to include the cctype library). CODE PROVIDED: #include #include #include using namespace std; string solve(string userStr) {    int start;    if(userStr[0]=='-' && isdigit(userStr[1])){       start=1;    }    else{       start=0;    }    for(int i=start; i

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter9: Completing The Basics
Section9.4: Character Manipulation Functions
Problem 5E
icon
Related questions
Question

C++ 10.17

Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs Yes if every character is a digit 0-9.

Ex: If the input is:

1995

the output is:

Yes

Ex: If the input is:

42,000

or

1995!

the output is:

No

Hint: Use a loop and the isdigit() function (don't forget to include the cctype library).

CODE PROVIDED:

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

string solve(string userStr) {
   int start;
   if(userStr[0]=='-' && isdigit(userStr[1])){
      start=1;
   }
   else{
      start=0;
   }
   for(int i=start; i<userStr.length();i++){
      if(!isdigit(userStr[i])){
         return "No";
      }
   return "Yes"
   }

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Program with must be output and correct & complete solution pl

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Basics of loop
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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr