#include <stdio.h> // Include standard I/O libraries
#include <stdlib.h> // Include standard libraries
#include <math.h> // Include Math libraries
/* Defining tax rates for Kudler's three store */
float DelMarRate = 7.25; /* Del Mar tax rate */
float EncinitasRate = 7.5; /* Encintas tax rate */
float LaJollaRate = 7.75; /* LaJolla tax rate */
/* Variables for Kudler's three store's tax calculation */
float DelMarTax = 0.0; /* Calculation variable for Del Mar taxes */
float EncinitasTax = 0.0; /* Calculation variable for Encintas taxes */
float LaJollaTax = 0.0; /* Calculation variable for LaJolla taxes */
float Amount = 0.0;
main()
{
char Purchase[32]; /* Declare variables */
int i,Return=0;
/* Prompt user for Purchase Amount */
printf("\n*********************************");
printf("\n* Welcome to Kudler Fine foods! *");
printf("\n*********************************");
printf("\n\n");
printf("\n\nPlease Enter the customer's purchase amount:$");
scanf("%s", Purchase);
/* Loop - Test the numeric values*/
for(i=0; Purchase[i]; i++)
{
if(Purchase[i] < '0' || Purchase[i] > '9') /* Test for a numeric value (0-9) */
{
if (Purchase[i] == '.') /* If character is a decimal continue */
continue;
else
Return=1; /* Set Non-Numerical Value flag */
break;
}
}
if (Return == 1) /* If Non-Numerical Value print Error Message */
{
printf("\n\nError! Invalid Purchase Amount [ %s ]\n",Purchase);
fflush(stdin);
printf("\n\nPlease Press The Enter Key To Exit Program!\n\n");
scanf("%c\n"); /*Keeping DOS Screen open so user can view output*/
return 0;
}
Amount=atof(Purchase); /* Convert to Float */
DelMarTax=(Amount*DelMarRate)/100; /* Calculate Tax Amount for Del Mar */
EncinitasTax=(Amount*EncinitasRate)/100; /* Calculate Tax Amount for Encinitas */
LaJollaTax=(Amount*LaJollaRate)/100; /* Calculate Tax Amount for La Jolla */
/* Display Tax Calculation output to the screen */
printf("\n\n\n");
printf("Del Mar\t\tEncinitas\tLa Jolla\t\n");
printf("*******************************************\n");
printf("$%.2f\t\t$%.2f\t\t$%.2f\n", DelMarTax, EncinitasTax, LaJollaTax);
printf("\n\nPlease Press The Enter Key To Exit Program!\n\n");
fflush(stdin);
/*Keeping DOS Screen open so user can view output*/
scanf("%c\n");
return 0;
}
Tax Calculator questionlooping program back to enter a new number after error is detected
Page 1 of 1
10 Replies - 960 Views - Last Post: 31 October 2009 - 12:57 PM
#1
Tax Calculator question
Posted 30 October 2009 - 05:39 PM
Replies To: Tax Calculator question
#2
Re: Tax Calculator question
Posted 30 October 2009 - 07:05 PM
#3
Re: Tax Calculator question
Posted 30 October 2009 - 08:19 PM
#include <stdio.h> // Include standard I/O libraries
#include <stdlib.h> // Include standard libraries
#include <math.h> // Include Math libraries
/* Defining tax rates for Kudler's three store */
float DelMarRate = 7.25; /* Del Mar tax rate */
float EncinitasRate = 7.5; /* Encintas tax rate */
float LaJollaRate = 7.75; /* LaJolla tax rate */
/* Variables for Kudler's three store's tax calculation */
float DelMarTax = 0.0; /* Calculation variable for Del Mar taxes */
float EncinitasTax = 0.0; /* Calculation variable for Encintas taxes */
float LaJollaTax = 0.0; /* Calculation variable for LaJolla taxes */
float Amount = 0.0;
int main(void)
{
char Purchase[32]; /* Declare variables */
int i,Return=0;
/* Prompt user for Purchase Amount */
printf("\n*********************************");
printf("\n* Welcome to Kudler Fine foods! *");
printf("\n*********************************");
printf("\n\n");
printf("\n\nPlease Enter the customer's purchase amount:$");
scanf("%s", Purchase);
/* Loop - Test the numeric values*/
for(i=0; Purchase[i]; i++)
{
if(Purchase[i] < '0' || Purchase[i] > '9') /* Test for a numeric value (0-9) */
{
if (Purchase[i] == '.') /* If character is a decimal continue */
continue;
else
Return=1; /* Set Non-Numerical Value flag */
break;
}
}
if (Return == 1) /* If Non-Numerical Value print Error Message and allow user to re-enter purchase price */
{
printf("\n\nError! Invalid Purchase Amount [ %s ]\n",Purchase);
fflush(stdin);
printf("\n\nPlease Re-enter Purchase Amount:$");
scanf("%s", Purchase); /*Keeping DOS Screen open so user can view output*/
}
Amount=atof(Purchase); /* Convert to Float */
DelMarTax=(Amount*DelMarRate)/100; /* Calculate Tax Amount for Del Mar */
EncinitasTax=(Amount*EncinitasRate)/100; /* Calculate Tax Amount for Encinitas */
LaJollaTax=(Amount*LaJollaRate)/100; /* Calculate Tax Amount for La Jolla */
/* Display Tax Calculation output to the screen */
printf("\n\n\n");
printf("Del Mar\t\tEncinitas\tLa Jolla\t\n");
printf("*******************************************\n");
printf("$%.2f\t\t$%.2f\t\t$%.2f\n", DelMarTax, EncinitasTax, LaJollaTax);
printf("\n\nPlease Press The Enter Key To Exit Program!\n\n");
fflush(stdin);
/*Keeping DOS Screen open so user can view output*/
scanf("%c\n");
return 0;
}
#4
Re: Tax Calculator question
Posted 30 October 2009 - 10:02 PM
#5
Re: Tax Calculator question
Posted 30 October 2009 - 10:08 PM
jbeme, on 30 Oct, 2009 - 09:02 PM, said:
#7
Re: Tax Calculator question
Posted 31 October 2009 - 08:57 AM
JackOfAllTrades, on 31 Oct, 2009 - 07:51 AM, said:
So, is University of Phoenix still requiring that you use Miracle C as your compiler?
#8
Re: Tax Calculator question
Posted 31 October 2009 - 09:01 AM
You can't tell us your code doesn't work or causes errors and expect decent help without providing the exact code causing such errors and the exact errors you are experiencing.
#9
Re: Tax Calculator question
Posted 31 October 2009 - 09:45 AM
#include <stdio.h> // Include standard I/O libraries
#include <stdlib.h> // Include standard libraries
#include <math.h> // Include Math libraries
/* Defining tax rates for Kudler's three store */
float DelMarRate = 7.25; /* Del Mar tax rate */
float EncinitasRate = 7.5; /* Encintas tax rate */
float LaJollaRate = 7.75; /* LaJolla tax rate */
/* Variables for Kudler's three store's tax calculation */
float DelMarTax = 0.0; /* Calculation variable for Del Mar taxes */
float EncinitasTax = 0.0; /* Calculation variable for Encintas taxes */
float LaJollaTax = 0.0; /* Calculation variable for LaJolla taxes */
float Amount = 0.0;
int main(void)
{
char Purchase[32]; /* Declare variables */
int i,Return=0;
/* Prompt user for Purchase Amount */
printf("\n*********************************");
printf("\n* Welcome to Kudler Fine foods! *");
printf("\n*********************************");
printf("\n\n");
printf("\n\nPlease Enter the customer's purchase amount:$");
scanf("%s", Purchase);
do{
/* Loop - Test the numeric values*/
for(i=0; Purchase[i]; i++)
{
if(Purchase[i] < '0' || Purchase[i] > '9') /* Test for a numeric value (0-9) */
{
if (Purchase[i] == '.') /* If character is a decimal continue */
continue;
else
Return=1; /* Set Non-Numerical Value flag */
break;
}
}
if (Return == 1) /* If Non-Numerical Value print Error Message and allow user to re-enter purchase price */
{
printf("\n\nError! Invalid Purchase Amount [ %s ]\n",Purchase);
fflush(stdin);
printf("\n\nPlease Re-enter Purchase Amount:$");
scanf("%s", Purchase);
}
}while (Return == 1);
Amount=atof(Purchase); /* Convert to Float */
DelMarTax=(Amount*DelMarRate)/100; /* Calculate Tax Amount for Del Mar */
EncinitasTax=(Amount*EncinitasRate)/100; /* Calculate Tax Amount for Encinitas */
LaJollaTax=(Amount*LaJollaRate)/100; /* Calculate Tax Amount for La Jolla */
/* Display Tax Calculation output to the screen */
printf("\n\n\n");
printf("Del Mar\t\tEncinitas\tLa Jolla\t\n");
printf("*******************************************\n");
printf("$%.2f\t\t$%.2f\t\t$%.2f\n", DelMarTax, EncinitasTax, LaJollaTax);
printf("\n\nPlease Press The Enter Key To Exit Program!\n\n");
fflush(stdin);
/*Keeping DOS Screen open so user can view output*/
scanf("%c\n");
return 0;
}
This post has been edited by mistymoon1966: 31 October 2009 - 11:33 AM
#10
Re: Tax Calculator question
Posted 31 October 2009 - 12:51 PM
#11
Re: Tax Calculator question
Posted 31 October 2009 - 12:57 PM
JackOfAllTrades, on 31 Oct, 2009 - 11:51 AM, said:
By the way if anyone in my class is reading these forums DO NOT COPY MY CODE as this is my own original code and I will show this thread to the instructor if need be, thanks.
Amanda Smith
CSS 561
|
|

New Topic/Question
Reply




MultiQuote




|