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

#include <iostream>

using namespace std;

void m0()
{
    unsigned int noReads = 0;
    unsigned int x = 0;
    printf("Enter a number: \n");
    while (true) 
    {
        noReads = scanf("%u", &x); 
        if (noReads == 1) break;
        printf("Enter a number: \n");
        while ((getchar()) != '\n');
     }
    printf("Number is: %s\n", x % 2 == 0 ? "even" : "odd");  
}

void m1()
{
    unsigned int noReads = 0;
    unsigned int x = 0;
    char buffer[80];
    printf("Enter a number: \n");
    while (fgets(buffer, sizeof(buffer), stdin)) 
    {
        noReads = sscanf(buffer, "%u", &x); 
        if (noReads == 1) break;
        printf("Enter a number: \n");
    }
    printf("Number is: %s\n", x % 2 == 0 ? "even" : "odd");
}

void m2()
{
    unsigned int noReads = 0;
    unsigned int x = 0;
    char *ptr = nullptr;
    char buffer[80];
    printf("Enter a number: \n");
    while (fgets(buffer, sizeof(buffer), stdin)) 
    {
        x = strtol(buffer, &ptr, 10);
        if (*ptr == '\n') break;
        printf("Enter a number: \n");
    }
    printf("Number is: %s\n", x % 2 == 0 ? "even" : "odd");
}


void m3()
{
    unsigned int x = 0;
    while(true)
    {
        cout << "Enter a number: ";
        cout.flush();
        if (cin >> x) break;
        cin.clear();
        cin.ignore(512, '\n');
    }
    cout << "Number is: " << (x % 2 == 0 ? "even" : "odd") << endl;
}



int main()
{
    //m0();               // "123" -> 123, "123asd" -> 123, "123 123" -> 123, "asd123" -> REPEAT, "asd" -> REPEAT, "asd 123" -> REPEAT
    //m1();               // "123" -> 123, "123asd" -> 123, "123 123" -> 123, "asd123" -> REPEAT, "asd" -> REPEAT, "asd 123" -> REPEAT
    //m2();               // "123" -> 123, "123asd" -> REPEAT, "123 123" -> REPEAT, "asd123" -> REPEAT, "asd" -> REPEAT, "asd 123" -> REPEAT
    m3();               // "123" -> 123, "123asd" -> REPEAT, "123 123" -> 123, "asd123" -> REPEAT, "asd" -> REPEAT, "asd 123" -> REPEAT
}