473,387 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help with isdigit

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
  1.  
  2. #include<stdio.h> //Loads standard input/output library
  3. #include<ctype.h>
  4.  
  5. main()
  6. { //Begin main
  7.  
  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 
  12.  
And here is my section were I have trouble with the isdigit:

Expand|Select|Wrap|Line Numbers
  1.  
  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);
  10.  
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.     }    
  6.  
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
2 4382
Banfa
9,065 Expert Mod 8TB
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
Ok, thanks Banfa, I will look in your link.
Nov 19 '08 #3

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

Similar topics

3
by: Mahmood Ahmad | last post by:
Hello, I have written a program that reads three types of records, validates them acording to certain requirements and writes the valid records into a binary file. The invalid records are...
7
by: Skysword | last post by:
Hi there, I got a problem with this. If I have a fuction like the following bool valid(int m, int n) { if(!isdigit(m)||!isdigit(n)) return false; else return true; } int main()
4
by: James Gregory | last post by:
I read that the argument to isdigit() can be "an integer whose value is representable as an unsigned char, or the value of the macro EOF.". This seems to say that it should work for values greater...
15
by: Carramba | last post by:
hi! I am trying to confirm if input is digit, so I thought it would by easy to do it with with isdigit() funktion, but how do I pass arrays to it if the imput is more then 1 sign? #include...
7
by: Per Rollvang | last post by:
Hi All! I have a problem with hex strings when using Char.IsDigit(). The hex strings(i.e. a CRC32 checksum) get a false result for letters A-F... MSDN tell me that: Indicates whether a...
4
by: Anoop | last post by:
Hi All I am getting two different outputs when i do an operation using string.digits and test.isdigit(). Is there any difference between the two. I have given the sample program and the output ...
10
by: mdh | last post by:
Could I get some help as to understanding why I am not getting a result I expect. #include <stdio.h> #include <ctype.h> int main (){ int i,j,k,c; i=9;
31
by: Martin Jørgensen | last post by:
Hi, I've had a introductory C++ course in the spring and haven't programmed in C++ for a couple of months now (but I have been programmed in C since january). So I decided to do my conversion...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.