Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, this program reads and integer, and checks whther it is even or odd. and als

ID: 3544264 • Letter: H

Question

Hi, this program reads and integer, and checks whther it is even or odd. and also adds up the even or odd ones using a print statement, please have a look it has a couple errors, once you fixed it, please explain in detail where the problem came from so I can understand it. thanks


#include <stdio.h>



int main(void)

{

    /* declare the variables. */

    int x;

    void checkifEvenorOdd(int);



    while (1)

    {


        printf(" Enter a positive integer ");


        scanf("%d", &x);


        if (x<=0)

        {


            break;

        }


        else

        {


           checkifEvenorOdd(x);



        }

    }

return 0;


    }

    int checkifEvenorOdd(int x)

    {

         if((x%2)==0) /* Checking whether remainder is 0 or not. if 0 then the enteed value is Even */

            {

            int countEven=0;

            countEven++;

            printf(" the number %d is even.",x);

            printf(" the total number of even integers is %d ",countEven);

            }

            else /* Checking whether remainder is 0 or not. if not 0 then the enteed value is Odd */

            {

            int countOdd=0;

            countOdd++;

            printf(" the number %d is odd ",x);

            printf(" the total number of odd integers is entered %d ",countOdd);

    }



Explanation / Answer

#include <stdio.h>



int main(void)

{

/* declare the variables. */

int x;

int checkifEvenorOdd(int); /**** previously u declared it as void, as returning an integer its return type should be int******/



while (1)

{


printf(" Enter a positive integer ");


scanf("%d", &x);


if (x<=0)

{


break;

}


else

{


checkifEvenorOdd(x);



}

}

return 0;


}

int checkifEvenorOdd(int x)

{

if((x%2)==0) /* Checking whether remainder is 0 or not. if 0 then the enteed value is Even */

{

int countEven=0;

countEven++;

printf(" the number %d is even.",x);

printf(" the total number of even integers is %d ",countEven);

}

else /* Checking whether remainder is 0 or not. if not 0 then the enteed value is Odd */

{

int countOdd=0;

countOdd++;

printf(" the number %d is odd ",x);

printf(" the total number of odd integers is entered %d ",countOdd);

}

} /****** u missed a closing brace here *****///

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote