Help with sample tax program

This is a discussion on Help with sample tax program within the C Programming forums, part of the General Programming Boards category; I am having trouble with a sample tax program that I am trying to write. If everything is working correctly, ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    4

    Question Help with sample tax program

    I am having trouble with a sample tax program that I am trying to write. If everything is working correctly, you should be able to enter a salary, and have state and federal taxes computed and printed on the screen along with corresponding salary. After entering all salaries, total salary and taxes should be printed. What I have so far is below. What am I doing wrong or missing? Thanks.


    #include <stdio.h>

    #define federal_rate .23 /* Federal Tax Rate */
    #define state_rate .07 /* State Tax Rate */

    double salary, total_salary , federal_taxes , total_federal_taxes , state_taxes , total_state_taxes ;


    int main(void){
    printf("Please enter a salary \n");
    while (scanf("%lf", &salary) == 1){
    federal_taxes = federal_rate * salary;
    state_taxes = state_rate * salary;
    printf("%s%5.2f\n%s%5.2f\n%s5.2f\n\n",
    "The salary is ",salary, "The federal tax
    is ",federal_taxes, "The state tax is ",state_taxes);
    total_salary += salary; total_federal_taxes += federal_taxes; total_state_taxes += state_taxes;
    printf("Please enter a salary \n");
    }
    printf("%s%5.2f\n%s5.2f\n%s%5.2f\n\n","Total salaries ",total_salary,"Total Federal taxes ",
    total_federal_taxes,"Total State taxes ",
    total_state_taxes);
    return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    1

    Cool

    Basically there isn't much problem with your program, to end your prgram with calculation of total salary,federal taxes and state taxes, just type in a few salaries and then type a single alphabet then your program will stop and give you the total.

    check this and compare with the on u posted-->
    printf("%s%5.2f\n%s%5.2f\n%s%5.2f\n\n","The salary is ",salary, "The federal tax is ",federal_taxes, "The state tax is ",state_taxes);

    you left out a "%"


    try this out.......

    #include <stdio.h>

    #define federal_rate .23 /* Federal Tax Rate */
    #define state_rate .07 /* State Tax Rate */

    double salary, total_salary , federal_taxes , total_federal_taxes , state_taxes , total_state_taxes ;


    int main(void)
    {
    printf("Please enter a salary \n");
    while (scanf("%lf", &salary) !=NULL )
    {
    federal_taxes = federal_rate * salary;
    state_taxes = state_rate * salary;
    printf("%s%5.2f\n%s%5.2f\n%s%5.2f\n\n","The salary is ",salary, "The federal tax is ",federal_taxes, "The state tax is ",state_taxes);
    total_salary += salary; total_federal_taxes += federal_taxes; total_state_taxes += state_taxes;
    printf("Please enter a salary \n");
    }

    printf("%s%5.2f\n%s%5.2f\n%s%5.2f\n\n","Total salaries ",total_salary,"Total Federal taxes ",total_federal_taxes,"Total State taxes ",total_state_taxes);
    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  2. End Program
    By jhwebster1 in forum C Programming
    Replies: 7
    Last Post: 02-24-2006, 08:30 AM
  3. help with basic program
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 02-01-2006, 03:19 PM
  4. Q on sample program
    By sean... in forum C++ Programming
    Replies: 6
    Last Post: 07-12-2004, 12:07 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21