| | |
Using isdigit
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 25
Reputation:
Solved Threads: 0
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;
Can someone please help me out?
Tyserman5674
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;
C Syntax (Toggle Plain Text)
/* 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"); } }
Tyserman5674
Last edited by Ancient Dragon; Jul 2nd, 2009 at 9:31 pm. Reason: correct code tags
Errors :
1> You cannot code like this.isdigit() is a function:
It should be
2>Be sure of the portability of
3>Your program has a lot of mistakes.
*
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???
1> You cannot code like this.isdigit() is a function:
c Syntax (Toggle Plain Text)
if isdigit(cResponse);
c Syntax (Toggle Plain Text)
if(isdigit(cResponse));
2>Be sure of the portability of
scanf_s 3>Your program has a lot of mistakes.
*
c Syntax (Toggle Plain Text)
{ 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); }
*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???
Last edited by csurfer; Jul 2nd, 2009 at 1:28 pm.
I Surf in "C"....
the answer to your basic problem:
is incorrect. it should be
(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.
.
c Syntax (Toggle Plain Text)
if isdigit(cResponse);
c Syntax (Toggle Plain Text)
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.
.
Last edited by jephthah; Jul 2nd, 2009 at 1:54 pm.
![]() |
Similar Threads
- isdigit ç à è (C++)
- Character handling problem! (isdigit) (C++)
- WinHugs - using isDigit (Legacy and Other Languages)
Other Threads in the C Forum
- Previous Thread: File problem in link list
- Next Thread: please hlep ()
| Thread Tools | Search this Thread |
* adobe ansi api array arrays binarysearch calculate centimeter char character cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking highest homework i/o inches incrementoperators intmain() iso km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. lowest match matrix microsoft mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pattern pdf performance posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprograming socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h windowsapi






