Asks the user for their birth year and calculates how old they will be in the current year. - C Operator

C examples for Operator:Arithmetic Operator

Description

Asks the user for their birth year and calculates how old they will be in the current year.

Demo Code

#include <stdio.h>
#define CURRENTYEAR 2020/* w w  w  . ja v  a2  s.co m*/

int main()
{
    int yearBorn, age;
    printf("What year were you born?\n");
    scanf(" %d", &yearBorn);

    if (yearBorn > CURRENTYEAR){
        printf("wrong input!\n");
        printf("What year were you born?\n");
        scanf(" %d", &yearBorn);
    }

    age = CURRENTYEAR - yearBorn;
    printf("\nSo this year you will turn %d on your birthday!\n",age);

    if ((yearBorn % 4) == 0){
        printf("\nYou were born in a Leap Year--cool!\n");
    }
    return 0;
}

Result


Related Tutorials