jeudi 1 octobre 2015

Prompting the user after an if statement in C?

I'm new to C and trying to write a simple program. I ask the user to enter a month. I know how to check if it's a valid month, but unsure how to prompt the user to enter another if it ISNT a valid month. Here is what I came up with:

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

int main(void)
{
    int mon;

    printf("Enter a month(1=Jan, ..., 12=Dec): ");
    scanf("%d", &mon);

    if (mon < 1)
        printf("Not a valid month.");
    else if (mon > 12)
        printf("Not a valid month");
    else
        ;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire