Now that you've traced through using the while loop to count the digits in integer, why don't you try summing the digits?
Complete the following file:
client.cpp
1 #include <iostream> 2 using namespace std; 3 4 int main() 5 6 int n = 134740; 7 int sum = 0; 8 9 while(n>0) 10 11 12 sum=sum+(n%10); 13 n=n/10; 14 } 15 16 17 cout << "The sum of the digits in " << n << " is " 18 } [Submit
Running program with substitutions
Actual
Expected
fail255523The sum of the digits in 0 is 22The sum of the digits in 255523 is 22
fail7
The sum of the digits in 0 is 7 The sum of the digits in 7 is 7
fail 9027
The sum of the digits in 0 is l8 The sum of the digits in 9027 is l8
fail158
The sum of the digits in 0 is l4 The sum of the digits in l58 is l4
fail91802