1. ## Another frustrated beginner...

Hi, beginner here. I have to write a program that will ask you for yearly income in U.S. dollars. The program will then calculate the income:

• in the U.S. after tax in U.S. dollars
• the same income in Great Britain after tax in Pounds.
• the same income in Germany after tax in Euros.

This is my second assignment for the class and am having a difficult time beginning the assignment. Will someone help me?

2. Any particular part you're having trouble with?
-User input
-Calculating the tax
-Subtracting the tax from the initial amount to get the net income

3. Originally Posted by hk_mp5kpdw
Any particular part you're having trouble with?
-User input
-Calculating the tax
-Subtracting the tax from the initial amount to get the net income
Or perhaps knowing the amount of tax in the different countries?

--
Mats

4. Subtracting the tax from the initial amount to get the net income

5. What have you tried?

--
Mats

6. Originally Posted by mfskratch
Subtracting the tax from the initial amount to get the net income
You'll probably have to take tax bands into account as well (I'm guessing you have those too in the US).
In the UK, you'd probably have to take off National Insurance contributions as well to get an accurate Net Income.

QuantumPete

7. QuantumPete: Yes, the US appears to have a variable tax rate for different income. This site http://www.paycheckcity.com/default.asp
has a "PayCheck calculator", where you can enter the amount of dollars a year you earn, and how much tax it results in. Entering \$20000 gives a federal tax of \$185 per month, and \$200000 gives a tax of over \$4000 per month, so a bit more than twice the linear expectation.

I couldn't find a simple table of how this works, but I expect that it's not too dissimilar from the UK system of paying one percentage for the first X amount, then a different percentage for the next Y amount, and so on.

--
Mats

8. This is what I have so far and I keep getting an error.

Code:
```#include "stdafx.h"
#include "stdio.h"

#define ust .20f
#define gbt .30f
#define gt .45f
#define er1 .498331f
#define er2 .722126f
#define usc 1.50f
#define gbc .99f
#define gc 1.99f

int _tmain(int argc, _TCHAR* argv[])
{
float usx;
float usy;

float gbx;

float gx;
float gy;

int usm;
int gbm;
int gm;

printf("Enter an income in dollars \n");

scanf("%f",&usx);

usy=usx-(usx*ust);
usm=int(usy/usc);
gx=usx*er2;
gy=gx-(gx*gt);
gm=int(gy/gc);

gbx=usx*er1;
gby=gbx-(gbx*gbt);
gbm=int(gby/gbc);

printf("\n                     Income          After Tax            Macs Purchased\n");

printf("\n       US            %.2f            %.2f                   %d",usx,usy,usm);
printf("\n    Germany          %.2f            %.2f                   %d",gx,gy,gm);
printf("\n  Great Britain      %.2f            %.2f                   %d",gbx,gby,gbm);

for(;;);
return 0;
}```

9. Yes, you are missing the gby variable, and you haven't got the right syntax for converting float to int - you need a "cast" like this:

Code:
`x = (int)(y - z);`
--
Mats

10. Thank you. I fixed the program.

11. Originally Posted by mfskratch
We have not learned about "casts" in my class yet... I am still having difficulties.
Well, you have now - at least the first simple version of. A cast is basicly saying to the compiler that "the left side of me is of THIS type, whether you think so or not, so make sure it works". Of course, this is both useful and dangerous, as if you don't quite know what you're doing, you may end up with something that doesn't do what you want.

Converting a float to integer is:
Code:
`x = (int) somefloat;`
Converting an int to a float is:
Code:
`somefloat = (float) x;`
Code:
`x = int(somefloat)`
, which doesn't work.

In your code, it works perfectly fine to completely ignore the "make this integer", because the compiler will provide an adequate conversion ANYWAYS, without complaining even the least bit, so if you have:
Code:
```    int x;
float y, z;
...
x = y / z;
...```
this will work just fine - no need to use casts.

--
Mats

12. Originally Posted by mfskratch
This is what I have so far and I keep getting an error.
In those cases it's always useful to post the errors, as well as the lines that they pertain to

QuantumPete