mercredi 19 août 2020

This code is supposed to output Even or Odd but it only outputs Odd [duplicate]

I am a beginner in C code, and for a challenge I coded a program that's supposed to tell if the number is Even or Odd, but all it outputs is Odd, even when I put an Even number.. Whats wrong? here is the code

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int in;
    int index = 0;
    char result[4];
    int oe = 0;
    scanf("%d", &in);

    while (index <= in) {
        index++;
        if (oe = 0){
            oe = 1;
        } else {
            oe = 0;
        }
    }

    if (oe = 0) {
        printf("Even");
    } else {
        printf("Odd");
    }
    return 0;
}

I think there is something wrong with the while loop, can you point it out?

Aucun commentaire:

Enregistrer un commentaire