I am trying to figure out how to add isdigit to my code to verify that the information entered is in numerical form. I have tried and tried but just cant get it.
this is what i have so far:
Code:
#include <stdio.h>//header
#include <ctype.h>//isdigit header
main()
{//start
int iResponse = 0;//town selection
float fCost;//calculation operator
fCost = 0;
printf ("\n\tThank you for using the Kudler tax calculation utility.\n");
printf ("\n\tPlease select your location to recieve your taxable total.\n");
Printf ("\n 1\tDel Mar\n");
Printf (" 2\tEncinitas\n");
Printf (" 3\tLa Jolla\n");
printf("\n Please select your location (1-3): ");
scanf("%d", &iResponse);
switch (iResponse)
{
case 1:
printf("\n Welcome Del Mar Associate.\n");
printf(" Please enter your sub-total: $");
scanf("\n%f", &fCost);//sale sub-total
printf(" --------------------------------\n");
printf(" Your total tax is $%.2f\n", fCost * .0725);//in-line calculation
printf(" The total amount owed is $%.2f\n", fCost * (1+.0725));//in-line calculation
break;
getchar();
case 2:
printf("\n Welcome Encinitas associate.\n");
printf(" Please enter your sub-total: $");
scanf("%f", &fCost);//sale sub-total
printf(" --------------------------------\n");
printf(" Your total tax is $%.2f\n", fCost * .075);//in-line calculation
printf(" The total amount owed is $%.2f\n", fCost * (1+.075));//in-line calculation
break;
getchar();
case 3:
printf("\n Welcome La Jolla associate.\n");
printf(" Please enter your sub-total: $");
scanf("%f", &fCost);//sale sub-total
printf(" --------------------------------\n");
printf(" Your total tax is $%.2f\n", fCost * .0775);//in-line calculation
printf(" The total amount owed is $%.2f\n", fCost * (1+.0775));//in-line calculation
break;
getchar();
}// end calc
getchar();//keeps application viewable on screen
}// end selection
I dont want anyone to do it for me. I just cant figure out how to add the
if \ else statements
would i place the if (isdigit) before the case statements or within them?
what about the else statements would i have just one? or one per case statement?
if anyone can give me a direction to go i would be most aprecieative.
thank you