Complete the function using a range loop. Given a string, return the sum of the digits 0-9 that appear in the string, ignoring all other characters. Return e if there are no digits in the string. main.cpp 1 2 #include

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 8PE: Write a program that reads in a line consisting of a students name, Social Security number, user ID,...
icon
Related questions
Question

C++ Programming 1

Complete the function using a range loop. Given a string, return the sum of the digits e-9 that|
appear in the string, ignoring all other characters. Return © if there are no digits in the string.
main.cpp
1
2 #include <string>
3 using namespace std;
4
int sumDigits(const string& s)
6 {
7
int sum{0};
// Write your loop here
8.
9
10
return sum;
11 }
Transcribed Image Text:Complete the function using a range loop. Given a string, return the sum of the digits e-9 that| appear in the string, ignoring all other characters. Return © if there are no digits in the string. main.cpp 1 2 #include <string> 3 using namespace std; 4 int sumDigits(const string& s) 6 { 7 int sum{0}; // Write your loop here 8. 9 10 return sum; 11 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning