Hi guys, here is the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
int iYearBorn = 0;
printf("\nEnter year born, either 2000, 2001, 2002: ");
scanf("%d", &iYearBorn);
if (isdigit(iYearBorn) == 0)
{
printf("\nInvalid Entry. Not a number! Program Terminating.\n");
return 0;
}
switch(iYearBorn)
{
case 2000:
printf("\n2000 is the year of luck!\n");
break;
case 2001:
printf("\nPeace be with you 2001\n");
break;
case 2002:
printf("\n2002 is uber leet pwnage dudez\n");
break;
default:
printf("\nNo data on that year!\n");
}
return 0;
}
What I want to do is check the user's input to make sure it's a number, if it's not a number I want it to display that message (Invalid Entry. Not a number! Program Terminating) and kill the program.
If it is a number I want it to continue on down to the switch statement etc, but the problem is, whenever I run it, no matter what the user input is, it ALWAYS says "Invalid Entry. Not a number! Program Terminating" and kills the program, even if I enter a number... so I'm assuming i'm using the isdigit function wrong somehow, if anyone could help me out that'd be great. Thanks!