Getting Odd of whole integer

Hi there.
> Get an integer, for example "1234"
> get "1" and "3"
> add both "1" and "3"

Need guidance please.


int sumOfOddDigits(int n)

{
int num1, num2, num3 , num4;
num1 = (n % 10) / 10;
num2 = num1 % 10;
num3 = (num2 % 10) / 10;
num4 = num3 % 10;
n = num1 + num4;

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

void digit_info(unsigned value)
{
    while (value)
    {
        unsigned digit = value % 10;

        std::cout << "Digit: " << digit << (digit % 2 ? " is odd." : " is even") << '\n';

        value /= 10;
    }
}

int main()
{
    digit_info(1234);
}
Thanks cire, I used a longer method but it worked

n % 100 / 10

n% 1000 / 100

Still thanks though.

Topic archived. No new replies allowed.