Can Someone Please Help Me Out With This Problem?
Author |
Message |
Newspaper
|
Posted: Tue Mar 20, 2012 4:54 pm Post subject: 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! |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Tue Mar 20, 2012 5:21 pm Post subject: 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). |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: Tue Mar 20, 2012 5:23 pm Post subject: RE:Can Someone Please Help Me Out With This Problem? |
|
|
You can start off by reading about how to do basic input, output, and variables and then about 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. ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Newspaper
|
Posted: Tue Mar 20, 2012 8:23 pm Post subject: 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 then
% formulas for an income of 27500 or less
amountTaxed := Income * taxOne
Income := Income - amountTaxed
put "Your income after taxes was $" ..
put Income : 0 : 2
elsif 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! |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Wed Mar 21, 2012 1:23 am Post subject: 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
|
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
|
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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Newspaper
|
Posted: Wed Mar 21, 2012 2:13 pm Post subject: 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! |
|
|
|
|
![](images/spacer.gif) |
|
|