• 0

C lang - isdigit


Question

Hi all,

Hoping to get some feedback on what im doing wrong here. Im new to programming in general so this is beginners stuff.

Goal:

writing a program in C language, using Miracle C compiler, that will receive a purchase amount and display the sale tax and total sale based on globally defined variables (tax rates).

Issue:

2 parts

first, im not sure im using "isdigit" correctly here. Feedback is very welcome :)

second, im getting a error on compile. I think its because of my else statement, I must be doing something wrong.

Heres my code:

//HEADER FILES

#include <stdio.h>

#include <ctype.h>

//GLOBAL VARIABLES

#define DM_TaxRate .0725

//MAIN FUNCTION

main()

{

//LOCAL VARIABLES

float fPurchase = 0;

float DMtax = 0;

printf("/nPlease enter the purchase amount: "); //input

scanf("%f", &fPurchase);

while (isdigit(fPurchase)){ //while condition to test validity of input

DMtax = fPurchase * DM_TaxRate; //calculation of tax

printf("/nThe tax at Del Mar is $%.2d.", DMtax); //display tax

printf("/nThe total at Del Mar is $%.2d.", DMtax + fPurchase); //calculate and display total sale

else //this is where im wrong I think

printf("/nPlease enter a valid dollar amount."); //response for invalid characters

} //end of loop

getchar(); //leaves program open so I can review

} //end of main function

Heres the error on compile, although most of you will probably see it right off the top (told ya it was beginners stuff).

line 22: Parse Error, expecting `'}''

'else'

aborting compile

Ive tried moving the brace around but I think its in the right spot. Im wondering if I can even use an "else" statement without an "if"..

Looking for any feedback, even if its not related to the issue at hand. Like I said, im new at this and learning so tips are appreciated. Thanks!

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.