tax calculation c and C++

I need rewrite the tax calculation using functions, and check invaild

Page 1 of 1

3 Replies - 4741 Views - Last Post: 13 February 2008 - 08:49 AM Rate Topic: -----

#1 tnj107  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-February 08

tax calculation c and C++

Posted 13 February 2008 - 07:21 AM

//Service Request: SR-kf-008 Tax from amount of sales input
// Change Request 2

#include <stdio.h>

/*Using define macros for assigning tax to different stores */
#define DelMar 7.25
#define Encinitas 7.5
#define LaJolla 7.75

/*
Input:
o Del Mar - 7.25%
o Encinitas - 7.5%
o La Jolla - 7.75%

Output:
The sales tax amount for each store of the 125.00 Purchase for each.
*/
float user_input(){
float amount;
printf("Please Enter the sales amount\n");
scanf("%f", &amount);
return amount;
}

int displayMenu(){
int choice;
printf("1. Del Mar - (7.25%%)\n");
printf("2. Encinitas - (7.5%%)\n");
printf("3. La Jolla - (7.75%%)\n");
printf("\n\nSelect a store for tax calculation [1-3]:");

scanf("%d",&choice);
return choice;
}

int main(){
// The total sales for each store is
float sales = 125.00;
int storenum;

sales = user_input();
if (sales < 0.0) {
printf("Error! Sales cannot be negative");
(-1);
}

storenum = displayMenu();

//Display Program Header
printf("Tax Calculator for Kudler Fine Foods for All 3 locations\n\n\n");

printf("STORE LOCATION\tSALES AMOUNT\tTAX RATE\tTAX AMOUNT\n");
printf("==============\t============\t========\t==========\n");
printf("==============\t============\t========\t==========\n");

switch (storenum){
case 1:
//Calculate and print the store location, Sales, Tax rate, and Tax amnt for Del Mar
printf("Del Mar \t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, DelMar, sales*DelMar/100);
break;
case 2:
//Calculate and print the store location, Sales, Tax rate, and Tax amnt for Encinitas
printf("Encinitas\t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, Encinitas, sales*Encinitas/100);
break;
case 3:
//Calculate and print the store location, Sales, Tax rate, and Tax amnt for La Jolla
printf("La Jolla \t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, LaJolla, sales*LaJolla/100);
break;
} //Switch ends
printf("================================================================\n");
printf(" +++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" Press ENTER to Exit Program \n");
printf(" +++++++++++++++++++++++++++++++++++++++++++++++++\n");
getchar();

return 0;

}

Is This A Good Question/Topic? 0
  • +

Replies To: tax calculation c and C++

#2 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: tax calculation c and C++

Posted 13 February 2008 - 07:50 AM

//Service Request: SR-kf-008 Tax from amount of sales input
// Change Request 2

#include <stdio.h>

/*Using define macros for assigning tax to different stores */
#define DelMar 7.25
#define Encinitas 7.5
#define LaJolla 7.75

/*
Input:
o Del Mar - 7.25%
o Encinitas - 7.5%
o La Jolla - 7.75%

Output:
The sales tax amount for each store of the 125.00 Purchase for each.
*/
float user_input(){
	float amount;
	printf("Please Enter the sales amount\n");
	scanf("%f", &amount);
	return amount;
}

int displayMenu(){
	int choice;
	printf("1. Del Mar - (7.25%%)\n");
	printf("2. Encinitas - (7.5%%)\n");
	printf("3. La Jolla - (7.75%%)\n");
	printf("\n\nSelect a store for tax calculation [1-3]:");

	scanf("%d",&choice);
	return choice;
}

int main(){
	// The total sales for each store is
	float sales = 125.00;
	int storenum;

	sales = user_input();
		if (sales < 0.0) {
		printf("Error! Sales cannot be negative");
		return (-1);
	}

	storenum = displayMenu();
		switch (storenum){
		case 1:
			//Calculate and print the store location, Sales, Tax rate, and Tax amnt for Del Mar
			printf("Del Mar \t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, DelMar, sales*DelMar/100);
			break;

		case 2:
			//Calculate and print the store location, Sales, Tax rate, and Tax amnt for Encinitas
			printf("Encinitas\t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, Encinitas, sales*Encinitas/100);
			break;

		case 3:
			//Calculate and print the store location, Sales, Tax rate, and Tax amnt for La Jolla
			printf("La Jolla \t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, LaJolla, sales*LaJolla/100);
			break;

		default:
			printf("Invalid Input.\n");
			return -1;
			break;

	} //Switch ends
	//Display Program Header
	printf("Tax Calculator for Kudler Fine Foods for All 3 locations\n\n\n");
	
	printf("STORE LOCATION\tSALES AMOUNT\tTAX RATE\tTAX AMOUNT\n");
	printf("==============\t============\t========\t==========\n");
	printf("==============\t============\t========\t==========\n");



	printf("================================================================\n");
	printf(" +++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf(" Press ENTER to Exit Program \n");
	printf(" +++++++++++++++++++++++++++++++++++++++++++++++++\n");
	getchar();

	return 0;

}



This is for the invalid inputs. Tell me how much you know about functions and passing parameters to functions.
Was This Post Helpful? 0
  • +
  • -

#3 tnj107  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-February 08

Re: tax calculation c and C++

Posted 13 February 2008 - 08:31 AM

Not much i am confused on how to to rewrite the program using functions????

View Postletthecolorsrumble, on 13 Feb, 2008 - 07:50 AM, said:

//Service Request: SR-kf-008 Tax from amount of sales input
// Change Request 2

#include <stdio.h>

/*Using define macros for assigning tax to different stores */
#define DelMar 7.25
#define Encinitas 7.5
#define LaJolla 7.75

/*
Input:
o Del Mar - 7.25%
o Encinitas - 7.5%
o La Jolla - 7.75%

Output:
The sales tax amount for each store of the 125.00 Purchase for each.
*/
float user_input(){
	float amount;
	printf("Please Enter the sales amount\n");
	scanf("%f", &amount);
	return amount;
}

int displayMenu(){
	int choice;
	printf("1. Del Mar - (7.25%%)\n");
	printf("2. Encinitas - (7.5%%)\n");
	printf("3. La Jolla - (7.75%%)\n");
	printf("\n\nSelect a store for tax calculation [1-3]:");

	scanf("%d",&choice);
	return choice;
}

int main(){
	// The total sales for each store is
	float sales = 125.00;
	int storenum;

	sales = user_input();
		if (sales < 0.0) {
		printf("Error! Sales cannot be negative");
		return (-1);
	}

	storenum = displayMenu();
		switch (storenum){
		case 1:
			//Calculate and print the store location, Sales, Tax rate, and Tax amnt for Del Mar
			printf("Del Mar \t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, DelMar, sales*DelMar/100);
			break;

		case 2:
			//Calculate and print the store location, Sales, Tax rate, and Tax amnt for Encinitas
			printf("Encinitas\t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, Encinitas, sales*Encinitas/100);
			break;

		case 3:
			//Calculate and print the store location, Sales, Tax rate, and Tax amnt for La Jolla
			printf("La Jolla \t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, LaJolla, sales*LaJolla/100);
			break;

		default:
			printf("Invalid Input.\n");
			return -1;
			break;

	} //Switch ends
	//Display Program Header
	printf("Tax Calculator for Kudler Fine Foods for All 3 locations\n\n\n");
	
	printf("STORE LOCATION\tSALES AMOUNT\tTAX RATE\tTAX AMOUNT\n");
	printf("==============\t============\t========\t==========\n");
	printf("==============\t============\t========\t==========\n");



	printf("================================================================\n");
	printf(" +++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf(" Press ENTER to Exit Program \n");
	printf(" +++++++++++++++++++++++++++++++++++++++++++++++++\n");
	getchar();

	return 0;

}



This is for the invalid inputs. Tell me how much you know about functions and passing parameters to functions.

Was This Post Helpful? 0
  • +
  • -

#4 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: tax calculation c and C++

Posted 13 February 2008 - 08:49 AM

check this topic:

Check out the code in the post by baavgai.


If you still find it difficult, post your questions here and help will be on the way.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1