print out even number from input using pointer

I'm a super beginner

The only way I know how to print out even numbers is using a division.

but the start form I'm given is below


void validateUserInput(char *UserInputCharArray, int &strLength);

int const ARRAY_SIZE = 100;

int main()
{
//required char pointer
char *UserInputCharArray = nullptr;

return 0;
}

void validateUserInput(char *UserInputCharArray, int &strLength)
{



Please help me here
Thank you all in advance
Last edited on
¿how does your code relate to your question?


To see if a number is even if( some_number%2 == 0 )
I know that code already.

the code I wrote is provided from my professor to use.

that's why I'm really confused
It is unclear, but maybe you want to do something like this-
(Note that this is not for
super beginner
. You need to learn more about C++ to totally understand this...)

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
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

bool validateUserInput(char *UserInputCharArray, int &strLength);

int const ARRAY_SIZE = 100;

int main()
{
    //required char pointer
    char *UserInputCharArray = NULL;
    int length;

    // allocate dynamic memory
    UserInputCharArray = new char[ARRAY_SIZE];

    gets(UserInputCharArray);

    // get length of the string
    length = strlen(UserInputCharArray);

    if( validateUserInput(UserInputCharArray, length ) )
    {
        cout << "Even\n";
    }
    else
    {
        cout << "Odd\n";
    }

    // free the dynamic memory
    delete []UserInputCharArray;

    return 0;
}

bool validateUserInput(char *UserInputCharArray, int &strLength)
{
    char lastChar = UserInputCharArray[strLength - 1];

    // 48 is the ASCII code for '0'
    return ((int)lastChar - 48) % 2 == 0;
}


Topic archived. No new replies allowed.