Thread: Help with my program

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    3

    Help with my program

    #include <stdio.h>

    int main()
    {
    float overtime_week_day=14,overtime_weekend=5,total_over _time;
    float overtime_weekendpay,overtime_week_daypay,standard_ pay, normal_pay;
    float over_pay, new_pay1, new_pay2;
    float tax1, tax2, tax3,tax;

    standard_pay=19.73*35;

    total_over_time=overtime_weekend+overtime_week_day ;
    overtime_weekendpay=overtime_weekend*(1.25*19.73);
    overtime_week_daypay=overtime_week_day*(1.5*19.73) ;


    over_pay=overtime_weekendpay+overtime_week_daypay;
    normal_pay=standard_pay+over_pay;

    {
    if(normal_pay>=200)
    {
    tax1=(30/100)*normal_pay;
    new_pay1=normal_pay-tax1;
    }
    else if(new_pay1>=300)
    {
    tax2=(40/100)*normal_pay;
    new_pay2=new_pay1-tax2;
    }

    else if(new_pay2>=0)
    {
    tax3=(50/100)*new_pay2;
    }
    tax=tax1+tax2+tax3;
    }
    printf("\nThe normal week pay is %f, the overtime pay is %f, the tax deduction is %2f\n",normal_pay,over_pay,tax);

    return 0;
    }



    Output:
    The normal week pay is 1228.192383, the overtime pay is 537.642456, the tax deduction is -214748352.0000........

    i dunno wots wrong with my program i fink its the if else can some help me so that it returns the correct value for "tax deduction" safe...
    Last edited by aries_isis; 12-11-2004 at 08:37 AM.

  2. #2
    Registered User
    Join Date
    Dec 2004
    Posts
    25
    for one, your variables "total_over time" and "standard_ pay" have spaces in them. what is the correct value for "tax deduction"?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Please use [code][/code]Tags

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    3
    I fix the space....I dont know wot the actual value for the tax but the question says.... Income tax is paid at a rate of 30% on the £200 of a weeks pay, 40% on the next 300 and 50% on the remainder. thats where i thought of constructing the if else

    if(normal_pay>=200)
    {
    tax1=(30/100)*normal_pay;
    new_pay1=(normal_pay-tax1);
    }
    else if(new_pay1>=300)
    {
    tax2=(40/100)*normal_pay;
    new_pay2=(new_pay1-tax2);
    }

    else if(new_pay2>=0)
    {
    tax3=(50/100)*new_pay2;
    }

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Please use [code][/code]Tags

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    25
    this might help:
    Code:
    #include <stdio.h>
    
    int main()
    {
    float overtime_week_day=14,overtime_weekend=5,total_overtime;
    float overtime_weekendpay,overtime_week_daypay,standard_pay, normal_pay;
    float over_pay, new_pay1, new_pay2;
    float tax1, tax2, tax3,tax;
    
    standard_pay=19.73*35;
    
    total_overtime=overtime_weekend+overtime_week_day;
    overtime_weekendpay=overtime_weekend*(1.25*19.73);
    overtime_week_daypay=overtime_week_day*(1.5*19.73) ;
    
    
    over_pay=overtime_weekendpay+overtime_week_daypay;
    normal_pay=standard_pay+over_pay;
    
    {
    if(normal_pay>=200)
    {
    tax1=(30/100)*normal_pay;
    printf("tax1 = %f\n", tax1);
    new_pay1=normal_pay-tax1;
    printf("new_pay1 = %f\n", new_pay1);
    }
    else if(new_pay1>=300)
    {
    tax2=(40/100)*normal_pay;
    printf("tax2 = %f\n", tax2);
    new_pay2=new_pay1-tax2;
    printf("new_pay2 = %f\n", new_pay2);
    }
    
    else if(new_pay2>=0)
    {
    tax3=(50/100)*new_pay2;
    printf("tax3 = %f\n", tax3);
    }
    tax=tax1+tax2+tax3;
    printf("tax = %f\n", tax);
    }
    printf("\nThe normal week pay is %f, the overtime pay is %f, the tax deduction is %2f\n",normal_pay,over_pay,tax);
    
    return 0;
    }

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    25
    i now see that the code i posted also has spaces in those two variables. i wonder if something's wrong with the forum.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Well if you just copy/paste from the forum, then your post isn't much better than before.
    But if you copy/paste directly from your source code editor directly into code tags, the results are usually pretty good.

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
             tax1=(30/100)*normal_pay;
             tax2=(40/100)*normal_pay;
             tax3=(50/100)*new_pay2;
    Doing integer math means these will all be zero.
    Code:
             tax1=(30.0F/100)*normal_pay;
             tax2=(40.0F/100)*normal_pay;
             tax3=(50.0F/100)*new_pay2;
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    Registered User
    Join Date
    Dec 2004
    Posts
    25
    Quote Originally Posted by Salem
    Well if you just copy/paste from the forum, then your post isn't much better than before.
    But if you copy/paste directly from your source code editor directly into code tags, the results are usually pretty good.
    i copied from the board, pasted it in emacs, corrected the spacing errors, ... copied it from emacs, pasted it to the board, and the spacing errors are back after it is submitted. try it.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > float overtime_weekendpay,overtime_week_daypay,standard_ pay, normal_pay;
    Then it's perhaps the total lack of space everywhere else in the line
    Code:
    float overtime_weekendpay, overtime_week_daypay, standard_pay, normal_pay;

  12. #12
    Registered User
    Join Date
    Dec 2004
    Posts
    25
    seems like a bug in the forum software. this works:
    Code:
     float overtime_week_day=14, overtime_weekend=5, total_over_time;
    but this doesn't:
    Code:
     float overtime_week_day=14,overtime_weekend=5,total_over_time;

  13. #13
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    are you using tabs or spaces? Are you using the quick reply or the advanced text editor? What happens when you copy from emacs and paste into another text editor?

  14. #14
    Registered User
    Join Date
    Dec 2004
    Posts
    25
    Quote Originally Posted by Thantos
    are you using tabs or spaces? Are you using the quick reply or the advanced text editor? What happens when you copy from emacs and paste into another text editor?
    spaces. advanced text editor. it's the same.

  15. #15
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >spaces. advanced text editor. it's the same.
    Try using the standard editor, it's much more predictable.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM