Help with arrays and user-defined functions?

closed account (2UX23TCk)
......
Last edited on
You need to convert the char into an int.
Also you need to check for zero first, since 0 % 2 == 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void input (char number[], int size, int& oddNumbers, int& evenNumbers, int& zeros)
{
  int i, length;
  length = strlen (number);

  for (i = 0; i < length; i++)
  {
    int num = number[i] - '0';
    if (num == 0)
    {
      zeros++;
    }
    else if ( num % 2 == 0)
    {
      evenNumbers++;
    }
    else if (num % 2 != 0)
    {
      oddNumbers++;
    }
    
  }
}
Topic archived. No new replies allowed.