Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 02-06-2014, 07:46 PM   #1
In Runtime
 
tj107us's Avatar
 
Join Date: Apr 2010
Location: USA
Posts: 332
Default Homework Help!!!

Hey guys, I'm having trouble with my program, It suppose to take in a number as "totalSales" from the user and calculate the county and state tax and then calculate the total between the two. Then it displays all three answers( total, state, county) to console. But when I put in 4,545 as a number(totalSales) the county tax shows 4,545 instead of 90.9 that is suppose to be. I can't figure out whats going on!! The state tax works like it supposed to, but county tax don't and their the same besides the variable name. Oh by the way this is written in VB!!

thanks for any help you may have!!!
tj


p.s. I have to turn it in by Sunday night!!


works better like this:


Module Module1

Sub Main()

Dim totalSales As Double
Dim countyTax As Double
Dim stateTax As Double
Dim totalTax As Double


inputSales(totalSales)
calcCounty(totalSales, countyTax)
calcState(totalSales, stateTax)
calcTotal(countyTax, stateTax, totalTax)
printTax(totalSales, countyTax, stateTax)



Console.ReadLine()


End Sub


'FUNCTIONS


'inputData Function

Sub inputSales(ByRef totalSales)
Console.WriteLine("Enter the total sales for the month")
totalSales = Console.ReadLine()
End Sub



'calcCounty Function

Sub calcCounty(totalSales, ByRef countyTax)
countyTax = totalSales * 0.02
End Sub

'calcState Function

Sub calcState(totalSales, ByRef stateTax)
stateTax = totalSales * 0.04
End Sub


'totalTax Fucntion

Sub calcTotal(ByRef totalTax, stateTax, countyTax)
totalTax = countyTax + stateTax
End Sub


'PrintTax Function

Sub printTax(countyTax, stateTax, totalTax)
Console.WriteLine("The county tax is... " & countyTax)
Console.WriteLine("The state tax is... " & stateTax)
Console.WriteLine("The total tax for both State and County is... " & totalTax)
End Sub



End Module
Attached Files
File Type: txt TaxCal.txt (1.3 KB, 2 views)
__________________

__________________
Intel Core I7 930 OCed to 3.5Ghz
ASUS P6X58D-E Motherboard
(3x4Gb) of Kingston 1333Mhz RAM
Corsair 950 Watt PSU
Corsair H70 Cooler
ATI (AMD) 5770 GPU
WD 1Tb black HDD
WD 500Gb black HDD
All in a Cooler Master HAF 932 Case
tj107us is offline   Reply With Quote
Old 02-06-2014, 11:56 PM   #2
Site Team
 
celegorm's Avatar
 
Join Date: Sep 2006
Posts: 10,713
Send a message via AIM to celegorm
Default Re: Homework Help!!!

Simple fix actually. Take a look a the code below. You pass in code to PrintTax as total sales, county tax, state tax but the function accepts it in the order of county tax, state tax and total tax. That's why it's coming out weird.

Code:
printTax(totalSales, countyTax, stateTax)
        Sub printTax(countyTax, stateTax, totalTax)
__________________

__________________
"as a fanboy i refuse to admit it and will pull countless things out of my butt to disprove it"

Team Thelegorm! Total Kills: 21 (i iz in uor profile, editsing your sigz)
celegorm is offline   Reply With Quote
Old 02-07-2014, 10:07 AM   #3
In Runtime
 
tj107us's Avatar
 
Join Date: Apr 2010
Location: USA
Posts: 332
Default Re: Homework Help!!!

Thanks for the help! I changed the order of the arguments, but it still isn't working. Both county tax and state tax come out the same amount, and the total tax is the same amount as what I put in as input!!!. here is the modified code:

Module Module1

Sub Main()

Dim totalSales As Double
Dim countyTax As Double
Dim stateTax As Double
Dim totalTax As Double


inputSales(totalSales)
calcCounty(totalSales, countyTax)
calcState(totalSales, stateTax)
calcTotal(countyTax, stateTax, totalTax)
printTax(totalSales, countyTax, stateTax)



Console.ReadLine()


End Sub


'FUNCTIONS


'inputData Function

Sub inputSales(ByRef totalSales)
Console.WriteLine("Enter the total sales for the month")
totalSales = Console.ReadLine()
End Sub



'calcCounty Function

Sub calcCounty(totalSales, ByRef countyTax)
countyTax = totalSales * 0.02
End Sub

'calcState Function

Sub calcState(totalSales, ByRef stateTax)
stateTax = totalSales * 0.04
End Sub


'totalTax Fucntion

Sub calcTotal(ByRef totalTax, stateTax, countyTax)
totalTax = countyTax + stateTax
End Sub


'PrintTax Function

Sub printTax(totalTax, countyTax, stateTax)
Console.WriteLine("The county tax is... " & countyTax)
Console.WriteLine("The state tax is... " & stateTax)
Console.WriteLine("The total tax for both State and County is... " & totalTax)
End Sub



End Module
__________________
Intel Core I7 930 OCed to 3.5Ghz
ASUS P6X58D-E Motherboard
(3x4Gb) of Kingston 1333Mhz RAM
Corsair 950 Watt PSU
Corsair H70 Cooler
ATI (AMD) 5770 GPU
WD 1Tb black HDD
WD 500Gb black HDD
All in a Cooler Master HAF 932 Case
tj107us is offline   Reply With Quote
Old 02-07-2014, 05:56 PM   #4
In Runtime
 
tj107us's Avatar
 
Join Date: Apr 2010
Location: USA
Posts: 332
Default Re: Homework Help!!!

never mind guys I have figured it out!!
__________________
Intel Core I7 930 OCed to 3.5Ghz
ASUS P6X58D-E Motherboard
(3x4Gb) of Kingston 1333Mhz RAM
Corsair 950 Watt PSU
Corsair H70 Cooler
ATI (AMD) 5770 GPU
WD 1Tb black HDD
WD 500Gb black HDD
All in a Cooler Master HAF 932 Case
tj107us is offline   Reply With Quote
Old 02-07-2014, 10:30 PM   #5
Site Team
 
celegorm's Avatar
 
Join Date: Sep 2006
Posts: 10,713
Send a message via AIM to celegorm
Default Re: Homework Help!!!

Just landed and haven't looked at the second set, but what was wrong?

Sent from my SCH-I545 using Computer Forums mobile app
__________________
"as a fanboy i refuse to admit it and will pull countless things out of my butt to disprove it"

Team Thelegorm! Total Kills: 21 (i iz in uor profile, editsing your sigz)
celegorm is offline   Reply With Quote
Old 02-08-2014, 08:27 PM   #6
Daemon Poster
 
xtremezx2's Avatar
 
Join Date: Sep 2006
Posts: 915
Default Re: Homework Help!!!

Curious as to why you are doing everything by reference instead of just returning values from your functions...

for example inputSales should be:
Code:
Function inputSales() As Double
     Console.WriteLine("Enter the total sales for the month")
     Double totalSales = Console.ReadLine()
     return totalSales;
End Function
I guess if this is how your teacher is showing you, stick to it so you get a better grade, but generally if you only have one value to return it should be a function (even if you have more than one, it should be a function with a custom class to return).

Adam
xtremezx2 is offline   Reply With Quote
Old 02-11-2014, 07:05 AM   #7
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 7,999
Default Re: Homework Help!!!

Quote:
Originally Posted by celegorm View Post
Just landed and haven't looked at the second set, but what was wrong?

Sent from my SCH-I545 using Computer Forums mobile app
I suspect something to do with this:
(what was said earlier)
Code:
calcTotal(countyTax, stateTax, totalTax)
....
Sub calcTotal(ByRef totalTax, stateTax, countyTax)
totalTax = countyTax + stateTax
End Sub
and
Code:
printTax(totalSales, countyTax, stateTax)

Sub printTax(totalTax, countyTax, stateTax)
Console.WriteLine("The county tax is... " & countyTax)
Console.WriteLine("The state tax is... " & stateTax)
Console.WriteLine("The total tax for both State and County is... " & totalTax)
End Sub
the order that you pass IS relevant for a start

Passing parameters to a function in order A=1 B=2 C=3
but reciving them as CBA means that C=1 B=2 and A=3, because you pass reference to the memory location where they are stored, not the name of the variable.

so in the first instance the code was putting out funny data because variables were passed
Code:
printTax(totalSales, countyTax, stateTax)
Sub printTax(countyTax, stateTax, totalTax)
-so where he expected to show county tax, total sales is showing, where he expected to show state tax the county tax is showing and where he expected to show the total tax the state tax is showing.

In the second code block only half of the first problems are resolved.
Code:
printTax(totalSales, countyTax, stateTax)
Sub printTax(totalTax, countyTax, stateTax)
total tax is still filled with the data of total sales, though now state and county tax should be showing successfully.

the reason that County and state tax were showing as the same is this bit of code.

Code:
calcTotal(countyTax, stateTax, totalTax)
....
Sub calcTotal(ByRef totalTax, stateTax, countyTax)
totalTax = countyTax + stateTax
End Sub
again, you're passing and initialising values in weird weird ways

and should find that chaning that to

Code:
calcTotal(countyTax, stateTax, totalTax)
....
Sub calcTotal(countyTax, stateTax, ByRef totalTax)
totalTax = countyTax + stateTax
End Sub
works...

so to sum up.

change Line 11
Code:
printTax(totalSales, countyTax, stateTax)
to
Code:
printTax(totalTax, countyTax, stateTax)
and change Line 29
Code:
Sub calcTotal(ByRef totalTax, stateTax, countyTax)
to
Code:
Sub calcTotal(countyTax, stateTax, ByRef totalTax)
and it should work...



lessons learned pay attention to what you call your variables and how you order them when you pas functions!

(it would be nice if you posted your entire working code so that others could see the complete project all working.)
__________________

__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 11:02 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0