
-----------------------------------
Newspaper
Tue Mar 20, 2012 4:54 pm

Can Someone Please Help Me Out With This Problem?
-----------------------------------
Hi Guys.
I just decided to make an account on this website today due to some difficulty with this problem I have been assigned at school. I just switched classes to computer science and I need just a few pointers from you guys if anyone sees this. Can some one please tell me how to approach this problem? 

Federal income tax is to be levied in stages on taxable 
income. On the first $27,500 you pay 17%, on the next 
$27,500 you pay 24%, and on the rest 29%. Write a program 
to read in a taxable income and compute the federal tax 
payable to the nearest cent.

It is from the Turing Textbook. Much Thanks!

-----------------------------------
Tony
Tue Mar 20, 2012 5:21 pm

RE:Can Someone Please Help Me Out With This Problem?
-----------------------------------
The first step is to figure out how much money goes into that first 27,500 pile (and how much, if any, remains). Then you tax the pile, and repeat for the second and third time (but don't worry about that right away).

-----------------------------------
[Gandalf]
Tue Mar 20, 2012 5:23 pm

RE:Can Someone Please Help Me Out With This Problem?
-----------------------------------
You can start off by reading about how to do [url=http://compsci.ca/v3/viewtopic.php?t=9634]basic input, output, and variables and then about [url=http://www.compsci.ca/v2/viewtopic.php?t=14656]if structures, both of which might come in handy.  If you're clever, you can probably get away with not using if statements.

If you get stuck on something more specific, make sure to post some relevant code which demonstrates your problem.  Good luck. :)

-----------------------------------
Newspaper
Tue Mar 20, 2012 8:23 pm

Re: Can Someone Please Help Me Out With This Problem?
-----------------------------------
% this program was created by Kazim Haider
% this program was created on March 19th
% this program displays an income after it has been taxed according to the amount

% declare variables
var taxOne : real := 0.017
var taxTwo : real := 0.024
var taxThree : real := 0.029
var income : string
var Income : real
var amountTaxed : real
var amountTaxed2 : real
var amountTaxed3 : real
var amountLeft : real
var amountLeft2 : real
var reply : string (1)
loop
    % get user input
    loop
        put "Hello. Please enter your income ==>" ..
        get income
        exit when strrealok (income)
        put "Please enter an appropriate value!"
        delay (1000)
        cls
    end loop
    Income := strreal (income)
    % formulas and if statements
    if Income  27500 and Income < 55000 then
        % formulas for an income greater than 27500
        amountTaxed := 27500 * taxOne
        amountLeft := Income - 27500
        amountTaxed2 := taxTwo * amountLeft
        Income := Income - (amountTaxed + amountTaxed2)
        put "Your income after taxes was $" ..
        put Income : 0 : 2
    elsif Income > 55000 then
        % formulas for an income greater than 55000
        amountTaxed := 27500 * taxOne
        amountTaxed2 := taxTwo * 27500
        amountLeft2 := Income - 55000
        amountTaxed3 := taxThree * amountLeft2
        Income := Income - (amountTaxed + amountTaxed2 + amountTaxed3)
        put ""
        put "Your final income after taxes was $" ..
        put Income : 0 : 2
    end if
    put "Would you like to try again? Press x to exit or any other key to continue..." ..
    getch (reply)
    exit when reply = "x" or reply = "X"
    cls
end loop

Thanks for the positive feedback! This is what I ended up doing. Could someone please check if it is outputting the correct data? Also, please list any suggestions you have. Thanks a lot!

-----------------------------------
Tony
Wed Mar 21, 2012 1:23 am

RE:Can Someone Please Help Me Out With This Problem?
-----------------------------------
that looks reasonably well for the first attempt, although:

0.017 is 1.7%, not 17%.

[code]
var income : string 
var Income : real 
[/code]
this is hard to read. "income" is never really used as income anyway; something like "temp_string" is more descriptive.

[code]
put "Your income after taxes was $" .. 
put Income : 0 : 2 
[/code]
is repeated 3 times in your code. You can get away with no repetitions, if you place it in a location common to all income cases.

-----------------------------------
Newspaper
Wed Mar 21, 2012 2:13 pm

Re: Can Someone Please Help Me Out With This Problem?
-----------------------------------
Thanks a lot for the feedback guys! I finished and handed in the program after the suggested changes and my teacher said it was fine!
