Thread: Another frustrated beginner...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Location
    Lowell, MA
    Posts
    9

    Unhappy 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. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    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
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by hk_mp5kpdw View Post
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Location
    Lowell, MA
    Posts
    9
    Subtracting the tax from the initial amount to get the net income

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What have you tried?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by mfskratch View Post
    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
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Sep 2007
    Location
    Lowell, MA
    Posts
    9

    Thumbs down

    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. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Sep 2007
    Location
    Lowell, MA
    Posts
    9
    Thank you. I fixed the program.
    Last edited by mfskratch; 09-25-2007 at 07:54 AM.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mfskratch View Post
    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;
    In your code, you had (the equivalent of)
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by mfskratch View Post
    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
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  2. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM
  3. so confused and frustrated
    By ct26torr in forum C Programming
    Replies: 2
    Last Post: 02-13-2003, 10:40 PM
  4. frustrated beginner
    By JCK in forum C++ Programming
    Replies: 4
    Last Post: 11-11-2002, 09:38 PM