tax calculation c and C++

Page 1 of 1

3 Replies - 5190 Views - Last Post: 13 February 2008 - 08:49 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=43190&amp;s=9cdfc659eae8306db5192517a3beea0a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 tnj107

Reputation: 0
• 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;
scanf("%f", &amount);
return amount;
}

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);
}

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

• Student of The Sun

Reputation: 27
• 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;
scanf("%f", &amount);
return amount;
}

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);
}

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
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.

#3 tnj107

Reputation: 0
• 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????

letthecolorsrumble, 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;
scanf("%f", &amount);
return amount;
}

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);
}

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
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.

#4 letthecolorsrumble

• Student of The Sun

Reputation: 27
• 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.