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
- #include<stdio.h> //Loads standard input/output library
- #include<ctype.h>
- main()
- { //Begin main
- float fSalePrice=0.00; //Declare as a float
- float fDelMar = 7.25; //Declare as a float
- float fEncinitas=7.50; //Declare as a float
- float fLaJolla=7.75; //Declare as a float
Expand|Select|Wrap|Line Numbers
- if (isdigit(fSalePrice)==0)
- {
- if(fSalePrice < 0.01 || fSalePrice > 1000000.00 )
- {
- printf("\n\n\nYou have entered an incorrect value.\n\n\n");
- printf("\nPlease enter a sale price between .01 and 1000000.00\n\n");
- printf("With out comma's, please enter the sale price of merchandice:$ ");
- scanf("%f",&fSalePrice);
Expand|Select|Wrap|Line Numbers
- else
- {
- printf("\n\nYou have entered a letter.\n\n");
- printf("Please enter a sale price between .01 and 1000000.00\n\n");
- }