How would you write it? 
Author Message
 How would you write it?

I'm writing a program that calculates the FIT tax of an Income.

if the salary is less than $20000 then FIT =  0
if income is between $20000 and $300000 then FIT = 15%
if income is over than $30000 then FIT = 28%

You would have to break your salary down like this:
For example:

if your salary is $50000
then, the first $20000 are free = 0  (now we have $30000)


Your final output would say something like FIT: 7100.00
--



Sun, 09 Mar 2003 03:00:00 GMT  
 How would you write it?

I would _not_ write this program; I do not do other people's homework.

Quote:
> I'm writing a program that calculates the FIT tax of an Income.

Good. Show us what it looks like and we may comment.

Richard
--



Sun, 09 Mar 2003 03:00:00 GMT  
 How would you write it?

Quote:

> I'm writing a program that calculates the FIT tax of an Income.

This sounds like a homework problem.  What did you try to do?  How far
did you get?

Remember, the idea of homework is that _you_ figure it out.  You won't
learn anything by turning in other peoples' homework.

--

 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ You must surely know / If man made Heaven, then man made Hell
\__/ Level 42
    Interstelen / http://www.interstelen.com/
 A multiplayer, strategic, turn-based Web game on an interstellar scale.
--



Sun, 09 Mar 2003 03:00:00 GMT  
 How would you write it?

Quote:
>Your final output would say something like FIT: 7100.00

Looks like a homework assignment.  A simple one, which doesn't involve
any of the non-trivial features/aspects of the language.

Dan
--
Dan Pop
CERN, IT Division

Mail:  CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland
--



Sun, 09 Mar 2003 03:00:00 GMT  
 How would you write it?


Quote:
>I'm writing a program that calculates the FIT tax of an Income.

>if the salary is less than $20000 then FIT =  0 if income is between
>$20000 and $300000 then FIT = 15% if income is over than $30000 then FIT
>= 28%

>You would have to break your salary down like this: For example:

>if your salary is $50000
>then, the first $20000 are free = 0  (now we have $30000) then, the{*filter*}

>Your final output would say something like FIT: 7100.00

And your question was?
Now if you want help with some homework, at least show us your attempt
and ask us for hints as to why it failed.

Francis Glassborow      Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
--



Sun, 09 Mar 2003 03:00:00 GMT  
 How would you write it?

Quote:
> I'm writing a program that calculates the FIT tax of an Income.

> if the salary is less than $20000 then FIT =  0
> if income is between $20000 and $300000 then FIT = 15%
> if income is over than $30000 then FIT = 28%

> You would have to break your salary down like this:
> For example:

> if your salary is $50000
> then, the first $20000 are free = 0  (now we have $30000)


> Your final output would say something like FIT: 7100.00

It seems that you've done a pretty good job breaking down the task into
steps that you can program. What is the problem?

Pieter.
--



Sun, 09 Mar 2003 03:00:00 GMT  
 How would you write it?
This is what I have so far....BUT it doesn't work the way it is supposse to. If
the user inputs $50000,  the final output looks correct but the Net Income
doesn't. Also, if I input something different than $50000...it seems like
everything is wrong.
Can somebody tell me what is wrong?

#include <stdio.h>
float main(void)

{
        float salary;
        float fica;
        float fit1 = 0;
        float fit2 = 10000 * .15;
        float total;
        float net;

        printf("Enter your salary:     ",salary);
        scanf("%f", &salary);
        printf("                       \n");
        printf("Income before tax:     %.2f\n", salary);
        printf("                       \n");
        printf("Taxes: \n");
        if (salary > 60000)
                printf("   FICA:    0.00\n");
        if (salary <= 60000)
                fica = salary * .075;
                printf("   FICA:    %.2f\n", fica);
        if (salary <= 20000)
                printf("   FIT:     %.2f\n", fit1);
        if (salary > 20000 && salary <= 30000)
                printf ("   FIT:     %.2f\n", fit2);
        if (salary > 30000)
                salary = salary - 30000;
                printf ("   FIT:     %.2f\n", (salary * .28) + fit2);
                total = (salary * .28) +fit2;
                printf ("   Total tax:        %.2f\n", fica + total);
                net = fica + total;
                printf ("Net Income:           %8.2f\n", (salary)+net);
        return 0;

Quote:
}

--



Mon, 10 Mar 2003 03:00:00 GMT  
 How would you write it?

Quote:

> This is what I have so far....BUT it doesn't work the way it is supposse
> to. If the user inputs $50000,  the final output looks correct but the Net
> Income doesn't. Also, if I input something different than $50000...it
> seems like everything is wrong. Can somebody tell me what is wrong?

> #include <stdio.h>
> float main(void)

 main returns an int.

Quote:
> {
>   float salary;
>   float fica;
>   float fit1 = 0;
>   float fit2 = 10000 * .15;
>   float total;
>   float net;

>   printf("Enter your salary:     ",salary);
>   scanf("%f", &salary);
>   printf("                       \n");
>   printf("Income before tax:     %.2f\n", salary);
>   printf("                       \n");
>   printf("Taxes: \n");

Why all the if's, many of them are redundant, and can be replaced by
else's.

Quote:
>   if (salary > 60000)
>       printf("   FICA:    0.00\n");

Are you sure that there is no FICA on incomes above $60,000?

Quote:
>   if (salary <= 60000)

    If both of these lines are to be pare of the if statement, use
curly-braces.

Quote:
>       fica = salary * .075;
>       printf("   FICA:    %.2f\n", fica);
>   if (salary <= 20000)
>       printf("   FIT:     %.2f\n", fit1);
>   if (salary > 20000 && salary <= 30000)
>       printf ("   FIT:     %.2f\n", fit2);
>   if (salary > 30000)
>       salary = salary - 30000;

    Just because you indented these following lines does not mean that
they are actually part of the if block. If you didn't want them to be
part of the if block, don't indent them (for readability by humans). If
you did want them to be part of the if block, put curly braces around
them.

Quote:
>       printf ("   FIT:     %.2f\n", (salary * .28) + fit2);
>       total = (salary * .28) +fit2;
>       printf ("   Total tax:        %.2f\n", fica + total);
>       net = fica + total;
>       printf ("Net Income:           %8.2f\n", (salary)+net);
>   return 0;

> }

I'm still not sure if this code will do what you want, but it is a bit
cleaner.

#include <stdio.h>

int main(void)
{
    float salary;
    float fica;
    float fit1 = 0;
    float fit2 = 10000 * .15;
    float total;
    float net;

    printf("Enter your salary:     ",salary);
    scanf("%f", &salary);
    printf("                       \n");
    printf("Income before tax:     %.2f\n", salary);
    printf("                       \n");
    printf("Taxes: \n");

    if (salary > 60000) {
        printf("   FICA:    0.00\n");
    }   else    {
        fica = salary * .075;
        printf("   FICA:    %.2f\n", fica);
    }

    if (salary <= 20000)    {
        printf("   FIT:     %.2f\n", fit1);
    }   else if (salary <= 30000)   {
        printf ("   FIT:     %.2f\n", fit2);
    }   else    {
        salary = salary - 30000;
        printf ("   FIT:     %.2f\n", (salary * .28) + fit2);
    }

    total = (salary * .28) +fit2;
    printf ("   Total tax:        %.2f\n", fica + total);
    net = fica + total;
    printf ("Net Income:           %8.2f\n", (salary)+net);
    return 0;

Quote:
}

--



Mon, 10 Mar 2003 03:00:00 GMT  
 How would you write it?

Quote:

> This is what I have so far....BUT it doesn't work the way it is supposse to. If
> the user inputs $50000,  the final output looks correct but the Net Income
> doesn't. Also, if I input something different than $50000...it seems like
> everything is wrong.
> Can somebody tell me what is wrong?

No. Your original problem only mentioned "FIT" but there's something called
"FICA" in here too. There are some issues that we can comment on, though.

Quote:
> #include <stdio.h>
> float main(void)

This must be a first, main returning a float. On all compilers I know,
main returns an int. With good reason, because that's what the standard
demands.

Quote:
> {
>         float salary;
>         float fica;
>         float fit1 = 0;
>         float fit2 = 10000 * .15;
>         float total;
>         float net;

I'm not sure why you need all these variables. You should
add comments describing them. I do miss the rates 15% and
28%, though.

Quote:
>         printf("Enter your salary:     ",salary);
>         scanf("%f", &salary);
>         printf("                       \n");
>         printf("Income before tax:     %.2f\n", salary);
>         printf("                       \n");
>         printf("Taxes: \n");
>         if (salary > 60000)
>                 printf("   FICA:    0.00\n");
>         if (salary <= 60000)
>                 fica = salary * .075;
>                 printf("   FICA:    %.2f\n", fica);

As I understand it, fica=7.5% of the salary if you earn less
then 60000, but if you earn more you pay no fica at all?

Quote:
>         if (salary <= 20000)
>                 printf("   FIT:     %.2f\n", fit1);

Useful, fit1. It's always 0.

Quote:
>         if (salary > 20000 && salary <= 30000)
>                 printf ("   FIT:     %.2f\n", fit2);

Shouldn't you calculate fit2? I.e.
fit2 = 15% of (salary over 20000) - 15% of (salary over 30000)

Quote:
>         if (salary > 30000)
>                 salary = salary - 30000;

What happens? Do you get a salary adjustment if it is over 30000?
I don't think so. You really should be calculating fit3 here,
as 28% of (salary over 30000).

Quote:
>                 printf ("   FIT:     %.2f\n", (salary * .28) + fit2);
>                 total = (salary * .28) +fit2;
>                 printf ("   Total tax:        %.2f\n", fica + total);
>                 net = fica + total;
>                 printf ("Net Income:           %8.2f\n", (salary)+net);

This is incorrectly indented. It's not part of the (if salary>30000).
Furthermore, FIT should be fit2+fit3. Total tax should be the (correct)
FICA + FIT, I guess. net should be salary - tax, and Net Income should
be net, not anything else.

Quote:
>         return 0;
> }

I'd say you don't have  a clear understanding of the problem. Can you
calcluate the correct values on paper? How? What intermediate steps
do you calculate? Now, translate this (working) algorithm into C.
Looking at your program I think you understand C well enough to
implement your algorithm.

Michiel Salters
--



Mon, 10 Mar 2003 03:00:00 GMT  
 How would you write it?

Quote:
>This is what I have so far....BUT it doesn't work the way it is supposse to. If
>the user inputs $50000,  the final output looks correct but the Net Income
>doesn't. Also, if I input something different than $50000...it seems like
>everything is wrong.
>Can somebody tell me what is wrong?

First off, use brackets to group the statements that are within the "if"
statements.  Unlike some languages, C does not use whitespace to denote
groupings of statements.

For example:
  if (X)
    foo();
    bar();

is actually the same as:
  if (X)
    {
    foo();
    }
  bar();

You want:
  if (X)
    {
    foo();
    bar();
    }

Quote:
>#include <stdio.h>
>float main(void)

>{
>    float salary;
>    float fica;
>    float fit1 = 0;
>    float fit2 = 10000 * .15;
>    float total;
>    float net;

>    printf("Enter your salary:     ",salary);
>    scanf("%f", &salary);
>    printf("                       \n");
>    printf("Income before tax:     %.2f\n", salary);
>    printf("                       \n");
>    printf("Taxes: \n");
>    if (salary > 60000)
>            printf("   FICA:    0.00\n");

No FICA if > than 60000?  Does not seem correct....  However, you never gave
the FICA req's for your program.

Quote:
>    if (salary <= 60000)
>            fica = salary * .075;
>            printf("   FICA:    %.2f\n", fica);

See note above on using brackets.  This is what I am talking about.  If your
income were greater than 60000, you would have two FICA lines, one with an
undefined value.

Quote:
>    if (salary <= 20000)
>            printf("   FIT:     %.2f\n", fit1);
>    if (salary > 20000 && salary <= 30000)
>            printf ("   FIT:     %.2f\n", fit2);

fit2 is defined as a constant 10000 * 0.15, but your requirements call for
15% of salary.  Shouldn't you be calculating FIT based on
(salary - 20000) * 0.15?

Quote:
>    if (salary > 30000)
>            salary = salary - 30000;
>            printf ("   FIT:     %.2f\n", (salary * .28) + fit2);
>            total = (salary * .28) +fit2;
>            printf ("   Total tax:        %.2f\n", fica + total);
>            net = fica + total;
>            printf ("Net Income:           %8.2f\n", (salary)+net);

More missing brackets, plus the logic is _way_ off....  First off, you will
want to calculate net income no matter what your salary is, so even if
you did put brackets in, if they matched your indenting, this would
not work, and if you had the net calc outside the last "if", you would be
adding fica (a value you only calculaged if salary <= 60000), to total (a
value you only calculated if salaray > 30000).  This will not work.
Finally, as much as I would like it to be true, taxes do not add to your
net pay, which is what you are in effect doing in the last line, after
deducting 30000 at first....

Based on my understanding of your original req's, I would use a running
total, something like (note, I only show FIT, not FICA, FICA is left
up to you, furthermore, I only show as little as possible to get my
point across, the details of making this work ar left up to you...)

   /*
    * start with nothing, figure out how much of the salary above
    * 20000 should be taxed at 15%.  This will be sal - 20000 if the
    * salary is < 30000, 10000 if >= 30000.  Therefore, the amount
    * taxed at 15% is obviously the minimum of those two....
    */
   fit = 0;
   if (salary > 20000)
     {
     temp = /* get the min of 10000 or (salary - 20000)
             * left as exercise to the reader */
     fit += temp * 0.15;
     }
   /*
    * This is simpler.  Anything over 30000 is just taxed at 28%.
    */
   if (salary > 30000)
     {
     fit += (salary - 30000) * 0.28;
     }

   /*
    * get the total tax, and the net pay
    */
   ttl_tax = fit + fica;
   net = salary - ttl_tax;

   /*
    * display your values....
    */

--
Ken Sodemann

http://www.execpc.com/~stuffle
--



Mon, 10 Mar 2003 03:00:00 GMT  
 How would you write it?

Quote:
>This is what I have so far....BUT it doesn't work the way it is supposse to. If
>the user inputs $50000,  the final output looks correct but the Net Income
>doesn't. Also, if I input something different than $50000...it seems like
>everything is wrong.
>Can somebody tell me what is wrong?

>#include <stdio.h>
>float main(void)

>{
>    float salary;
>    float fica;
>    float fit1 = 0;
>    float fit2 = 10000 * .15;
>    float total;
>    float net;

>    printf("Enter your salary:     ",salary);
>    scanf("%f", &salary);
>    printf("                       \n");
>    printf("Income before tax:     %.2f\n", salary);
>    printf("                       \n");
>    printf("Taxes: \n");
>    if (salary > 60000)
>            printf("   FICA:    0.00\n");
>    if (salary <= 60000)
>            fica = salary * .075;
>            printf("   FICA:    %.2f\n", fica);
>    if (salary <= 20000)
>            printf("   FIT:     %.2f\n", fit1);
>    if (salary > 20000 && salary <= 30000)
>            printf ("   FIT:     %.2f\n", fit2);
>    if (salary > 30000)
>            salary = salary - 30000;
>            printf ("   FIT:     %.2f\n", (salary * .28) + fit2);
>            total = (salary * .28) +fit2;
>            printf ("   Total tax:        %.2f\n", fica + total);
>            net = fica + total;
>            printf ("Net Income:           %8.2f\n", (salary)+net);
>    return 0;

>}

c is not indent sensitive.   When your if block is more than one
statement you must use braces.

<<Remove the del for email>>
--



Thu, 13 Mar 2003 10:46:08 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. NetworkStream.Write writes "sometimes"

2. Writing to write-protected folders.

3. using write() to write a struct to a file

4. Writing Written Text File at Specific Location in Each Line

5. Help wanted on reading/writing disk and writing your own OS

6. Cant write IStream::Write due to insufficient disk space

7. how to write Excel cells in application written by VC++ 6.0

8. write to file with CFile::Write() failed

9. I want to write *.INT but write in registry

10. Can't pass an std::basic_string object from app written in MS VC7 to dll written in MS VC6

11. Can't pass an std::basic_string object from app written in MS VC7 to dll written in MS VC6

12. Beginner needs advice on code-writing: How should I write the code?

 

 
Powered by phpBB® Forum Software