Hi Everyone,
I need help with using isdigit in C. What I am trying to do is verify that the user input is numeric. In my program, as is, I get the error:
line (21) : error C2061: syntax error : identifier 'isdigit'. If I remove the "if" from in front of the" isdigit" it will run but not give me the results that I need. It runs thru the program as if it where 0 and goes to my
3rd "if" statement, printing the you have 18 years to wait to vote, then it prints "You did not enter a digit".
Here is my code;

/* CSS 561 Prograqmming Concepts
Week 2 Assignment 
A program that prompts a user for his or her age, 
and computes whether they are old enough to vote – age 18.  
If they are too young, your program should inform them that 
they can vote in XX years.  If they are old enough, you should 
inform them that they have been eligible to vote for YY years. */
//by Ken Volkman
#include <stdio.h>
#include <ctype.h>
int main()

{
	int iResponse = 0;
	char cResponse = '\0';
		{
		printf("\n\tThis program will determine if you are old enough to vote:\n");
		printf("\n\tPlease enter your age; ");
		scanf_s("%d, %c", &iResponse, &cResponse);				
		}
	if isdigit(cResponse);

	{
		if(iResponse >=18)
		{
		printf("\n\tYou have been elgibale to vote for\n\t%d years now.\n\t", iResponse - 18);
		//printf("\n\t");
		printf("\n\t'Thank You'");
		printf("\n\n\t");
		}
		if(iResponse < 18)
		{
		printf("\n\tYou are not old enough to vote yet, \n\tbut you will be eligable in %d years.\n", 18 - iResponse);
		//printf("\n\t");
		printf("\n\t'Thank You'");
		printf("\n\n\t");
		}
	else
	printf("\n\tYou did not enter a didgit\n\n\t");
	}	

}

Can someone please help me out?
Tyserman5674

Errors :

1> You cannot code like this.isdigit() is a function:

if isdigit(cResponse);

It should be

if(isdigit(cResponse));

2>Be sure of the portability of scanf_s 3>Your program has a lot of mistakes.

*

{
printf("\n\tThis program will determine if you are old enough to vote:\n");
printf("\n\tPlease enter your age; ");
scanf_s("%d, %c", &iResponse, &cResponse);	
}

Useless Braces.

*The semicolon after your problematic if statement.With that its as good as not including that if statement.

*isdigit() checks for a digit 0 1 2 3 4 5 6 7 8 9 not for a number.

And many others so check.

And ya mainly use code tags.Is that so difficult???

the answer to your basic problem:

if isdigit(cResponse);

is incorrect. it should be

if (isdigit(cResponse))
{   
    // do stuff here
}

(1) an if-statement must be entirely enclosed in parentheses.

(2) an if-statement -- if the condition is evaluated as true -- will execute either one line of code terminated with a semi-colon or a block of code contained between the curly braces, '{' and '}'

so even if you framed the conditional statement correctly, since you put the semicolon directly after the if statement, it still would never execute anything when the condition evaluated true.

.

This question has already been answered. Start a new discussion instead.