help with modulus operator

i have a program that i need to write that requires the following output:

"the entered value is "23557" it has 5 digits with the digit sum of 22.
the number of 5's in the value is 2."

i need help adding the digits together and telling the program to count the number of how many digits there are. i've been told to use the modulus operator but i just cant figure out how to execute this.


here is what i have so far
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  #include <iostream>
#include <cmath>

long valueinput(long);


int main()
{
using namespace std;



long value, digits;

cout<< "enter value here: "<< endl;
cin>> value;

long givenvalue = valueinput(value);

digits=floor(log10(value))+1;
cout<< " the value entered is "<< value << " it has " << digits << " digits "<< " with the digit sum of " << givenvalue << endl;


system ("pause");
return 0;
}

long valueinput(long digits)
{
	return ;

}
when you do the modulus %, it will give you remainder.
using %:
in regular math, 23557/10 = 2355 remainder 7,
so that 23557% 10 = 7, then divide 23557/10 = 2355. (in C++, integer division will remove decimal).

then:
2355%10 = 5, then 2355/10 = 235. and so on, you will get all the digits.

set sum to 0, each time when you do modulus, you add the remainder to the sum.
Topic archived. No new replies allowed.