The program is supposed to receive purchase amount input, check validity, then calculate and display taxes and total at 3 locations.
The problem is I cant get it to compile when I trying to check input as being a digit. The program works fine otherwise, but I need this additional check or when a non-digit character is entered the program returns taxes and totals as 0.00.
if isdigit(fPurchase) { //this gives me a compile error expecting "(".
which seems that Miracle C wants me to change it to:
if (isdigit(fPurchase)) { //But that gives me: (null) parse error, expecting 'WHILE' ' '
which I do not understand.
Also, I may not be correct with the following 2 statements either, but if I can get it to compile the 'if' condition then I can probably figure that out.
Here's my code, all tips or corrections are appreciated greatly!!!
//HEADER FILES
#include <stdio.h>
#include <ctype.h>
//GLOBAL VARIABLES
#define DM_TaxRate 0.0725
#define E_TaxRate 0.075
#define LJ_TaxRate 0.0775
//MAIN FUNCTION
main()
{
//LOCAL VARIABLES
float fPurchase = 0.0; //input variable
float fPurchConfirm = 0.0; //input variable for validity check
do { //start do while loop
printf("\nPlease enter the purchase amount: $ "); //request input
scanf("%f", &fPurchase); //store input
printf("\nPlease confirm the purchase amount: $ "); //request input again to check validity
scanf("%f", &fPurchConfirm); //store input
if (isdigit(fPurchase)) {
continue;
printf("\nYou have entered a letter, please try again.");
Question
DanMan22
Hey im hoping to get some insight to this.
Using Miracle C compiler.
The program is supposed to receive purchase amount input, check validity, then calculate and display taxes and total at 3 locations.
The problem is I cant get it to compile when I trying to check input as being a digit. The program works fine otherwise, but I need this additional check or when a non-digit character is entered the program returns taxes and totals as 0.00.
if isdigit(fPurchase) { //this gives me a compile error expecting "(".
which seems that Miracle C wants me to change it to:
if (isdigit(fPurchase)) { //But that gives me: (null) parse error, expecting 'WHILE' ' '
which I do not understand.
Also, I may not be correct with the following 2 statements either, but if I can get it to compile the 'if' condition then I can probably figure that out.
Here's my code, all tips or corrections are appreciated greatly!!!
//HEADER FILES
#include <stdio.h>
#include <ctype.h>
//GLOBAL VARIABLES
#define DM_TaxRate 0.0725
#define E_TaxRate 0.075
#define LJ_TaxRate 0.0775
//MAIN FUNCTION
main()
{
//LOCAL VARIABLES
float fPurchase = 0.0; //input variable
float fPurchConfirm = 0.0; //input variable for validity check
do { //start do while loop
printf("\nPlease enter the purchase amount: $ "); //request input
scanf("%f", &fPurchase); //store input
printf("\nPlease confirm the purchase amount: $ "); //request input again to check validity
scanf("%f", &fPurchConfirm); //store input
if (isdigit(fPurchase)) {
continue;
printf("\nYou have entered a letter, please try again.");
}
while(fPurchase != fPurchConfirm); //checks validity
while(fPurchase == fPurchConfirm) { //condition
printf("\nThe tax at Del Mar is $%.2f.", fPurchase*DM_TaxRate); //calculates and displays Del Mar tax
printf("\nThe total at Del Mar is $%.2f.", fPurchase*DM_TaxRate+fPurchase); //calculate and display Del Mar total
printf("\n\nThe tax at Encinitas is $%.2f.", fPurchase*E_TaxRate); //calculate and display Encinitas tax
printf("\nThe total at Encinitas is $%.2f.", fPurchase*E_TaxRate+fPurchase); //calculate and display Encinitas total
printf("\n\nThe tax at La Jolla is $%.2f.", fPurchase*LJ_TaxRate); //calculate and display La Jolla tax
printf("\nThe total at La Jolla is $%.2f.", fPurchase*LJ_TaxRate+fPurchase); //calculate and display La Jolla total
break; //stops loop
}
getchar(); //leaves program open for review
} //end of main function
Link to comment
Share on other sites
3 answers to this question
Recommended Posts