By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,507 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,507 IT Pros & Developers. It's quick & easy.

Help with isdigit

P: 2
Hi Forum,

First let me begin by stating I am a student and have read the proper posting procedure concerning students. I am a begginer learning with the Miracle C Work Bench. I know my code is probably doing everything the long way, and there are more proficient ways to write my program, but like I said, I am just learning this foreign language. I'll get there!! (smiling)

Here is my problem, In my code I am trying to both verify that a user has input a number and not a letter and then verify that the number input will fall between a given range.

I have the range completed, but I am now trying to insert a number/letter validation using isdigit. I have the program working if a user inputs a number, it goes through isdigit and enters all my if/else statements correctly: however, if I input a letter, this completely throws my program for a loop, and no matter what I have tried will not work. I do not know if this is because I am using float-point numbers or what. It seems that when a letter is input it gets assigned to my float variable and goes through the wrong side of my code (like it was a number) and I can not get the input letter to flow the right way from isdigit. Here are my variable declarations and the peice of my code where I am having trouble. I hope this is enough for some one to get me pointed in the right direction, I have been working on this all night. It is not due for another two weeks. (I am working ahead in my class work)

Expand|Select|Wrap|Line Numbers
  2. #include<stdio.h> //Loads standard input/output library
  3. #include<ctype.h>
  5. main()
  6. { //Begin main
  8.     float fSalePrice=0.00; //Declare as a float
  9.     float fDelMar = 7.25; //Declare as a float
  10.     float fEncinitas=7.50; //Declare as a float
  11.     float fLaJolla=7.75; //Declare as a float 
And here is my section were I have trouble with the isdigit:

Expand|Select|Wrap|Line Numbers
  2. if (isdigit(fSalePrice)==0)
  3.     {        
  4.         if(fSalePrice < 0.01 || fSalePrice > 1000000.00 )
  5.         {
  6.             printf("\n\n\nYou have entered an incorrect value.\n\n\n");
  7.             printf("\nPlease enter a sale price between .01 and 1000000.00\n\n");
  8.             printf("With out comma's, please enter the sale price of merchandice:$ ");
  9.             scanf("%f",&fSalePrice);
Here is were I am trying to get a letter input to default to else statement)

Expand|Select|Wrap|Line Numbers
  1. else 
  2.     {
  3.         printf("\n\nYou have entered a letter.\n\n");
  4.         printf("Please enter a sale price between .01 and 1000000.00\n\n");
  5.     }    
I hope this enough for someone to help steer me, as I do want to learn what to do. Any direction would be greatly appreciated!
Nov 19 '08 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 8,916
You have mis-understood how the function isdigit works. I suggest you read your text book or if you look in the first thread of this forum PLEASE READ FIRST: Useful Links and Posting Guidelines you will find some links to a reference where you can look up and read about this function.
Nov 19 '08 #2

P: 2
Ok, thanks Banfa, I will look in your link.
Nov 19 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.