d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > Iso Visual Basic Help - Console Application > Paying 1000fg!
Add Reply New Topic New Poll
Member
Posts: 2,127
Joined: May 22 2011
Gold: 0.00
Oct 21 2013 10:39am
I need this code to work, right now this is what its doing and I am pretty stumped on what to do.
PROBLEMS:
1. It asks for "Please enter the sales for the month twice"
2. Even when I enter a value that is greater than 102500 it will still display "Sorry no bonus for the month"

I am new to this please help.



Code
Module Module1

Sub Main()
Dim sales As Double
Dim determineBonus As String
Dim determineDayOff As String

getSales()
determineBonus = cBonus(sales)
determineDayOff = checkDayOff(sales)
printInfo(determineBonus, determineDayOff)

End Sub

Function getSales()
Console.WriteLine("Please enter the sales for the month")
getSales = Console.ReadLine()
Return getSales
End Function

Function cBonus(ByVal getSales As Double)
Dim determineBonus As String = " "
If getSales >= 102500 Then
determineBonus = "You earned a bonus this month"
End If
If getSales < 102500 Then
determineBonus = "Sorry no bonus for the month"
End If
Return determineBonus
End Function

Function checkDayOff(ByVal getSales As Double)
Dim determineDayOff As String = " "
If getSales >= 112500 Then
determineDayOff = "All employees get a day off!"
Else
determineDayOff = "Sorry no earned day off"
End If
Return determineDayOff
End Function

Sub printInfo(ByRef determineBonus As String, ByRef determineDayOff As String)
Console.WriteLine("Your sales for the month was $" & getSales())
Console.WriteLine("Earned the monthly bonus? " & determineBonus)
Console.WriteLine("Earned day off? " & determineDayOff)
End Sub


End Module
Member
Posts: 21,893
Joined: Mar 27 2009
Gold: 12,408.00
Oct 21 2013 12:54pm
getSales is most likely not getting passed correctly, and it is defaulting on Else because it is read in as a string and "ByVal" doesn't magically turn it into a double I don't think.

I've never worked with VB before, only VBA (VB with Excel). It's almost the same syntax, just with Excel instead of console.

This post was edited by Dontrunaway on Oct 21 2013 12:55pm
Member
Posts: 2,127
Joined: May 22 2011
Gold: 0.00
Oct 21 2013 01:06pm
Thankyou Dontrunaway! but one more problem is that it is asking "Please enter the sales for the month" 4 times now! lol

Code
Module Module1

Sub Main()
Dim determineBonus As String
Dim determineDayOff As String

getSales()
determineBonus = cBonus(getSales)
determineDayOff = checkDayOff(getSales)
printInfo(determineBonus, determineDayOff)

End Sub

Function getSales()
Console.WriteLine("Please enter the sales for the month")
getSales = Console.ReadLine()
Return getSales
End Function

Function cBonus(ByRef getSales As Double)
Dim determineBonus As String = " "
If getSales >= 102500 Then
determineBonus = "You earned a bonus this month"
End If
If getSales < 102500 Then
determineBonus = "Sorry no bonus for the month"
End If
Return determineBonus
End Function

Function checkDayOff(ByRef getSales As Double)
Dim determineDayOff As String = " "
If getSales >= 112500 Then
determineDayOff = "All employees get a day off!"
Else
determineDayOff = "Sorry no earned day off"
End If
Return determineDayOff
End Function

Sub printInfo(ByRef determineBonus As String, ByRef determineDayOff As String)
Console.WriteLine("Your sales for the month was $" & getSales())
Console.WriteLine("Earned the monthly bonus? " & determineBonus)
Console.WriteLine("Earned day off? " & determineDayOff)
End Sub


End Module
Member
Posts: 21,893
Joined: Mar 27 2009
Gold: 12,408.00
Oct 21 2013 01:09pm
Quote (WTFisHIV @ Oct 21 2013 02:06pm)
Thankyou Dontrunaway! but one more problem is that it is asking "Please enter the sales for the month" 4 times now! lol



First name the actual variable getSales something other than getSales and change it throughout.

Also, you have a getSales() in your printInfo subroutine when it should just be the variable getSales

This post was edited by Dontrunaway on Oct 21 2013 01:09pm
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Oct 21 2013 01:27pm
I know almost no VB but I don't see where you declare the variable type for "getSales" and even more confusing your using getSales as a variable and a function. Now maybe this is allowed with VB, but it confuses the shit out of me :evil:

Code
Module VBModule

Sub Main()
dim sales as double
dim determineBonus as string

sales = getSales()

If sales >= 102500 Then
determineBonus = "You get a cookie!"
else
determineBonus = "No cookie for you!"
End If

Console.WriteLine(determineBonus)
End Sub

Function getSales()
dim sales_input as double
Console.WriteLine("Please enter the sales for the month")
sales_input = Console.ReadLine()
Return sales_input
End Function

End Module

Here is a quick snippet I wrote to do just that part.

This post was edited by Azrad on Oct 21 2013 01:35pm
Member
Posts: 21,893
Joined: Mar 27 2009
Gold: 12,408.00
Oct 21 2013 01:38pm
Quote (Azrad @ Oct 21 2013 02:27pm)
I know almost no VB but I don't see where you declare the variable type for "getSales" and even more confusing your using getSales as a variable and a function. Now maybe this is allowed with VB, but it confuses the shit out of me  :evil:

Code
Module VBModule

Sub Main()
    dim sales as double
    dim determineBonus as string
   
    sales = getSales()
   
    If sales >= 102500 Then
        determineBonus = "You get a cookie!"
    else
        determineBonus = "No cookie for you!"
    End If

    Console.WriteLine(determineBonus)
End Sub

Function getSales()
    dim sales_input as double
    Console.WriteLine("Please enter the sales for the month")
    sales_input = Console.ReadLine()
    Return sales_input
End Function
 
End Module

Here is a quick snippet I wrote to do just that part.


IIRC VB will define it for you if you don't tell it not to, so yeah it gets a little confusing if you don't dimension it.
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Oct 21 2013 01:45pm
I did some experimenting. Since you getSales is a function, every time you do something like:
Code
If getSales < 102500 Then
you are calling that function (so it asks for input again, and again, and again). Fucking VB is weird, you would think it would have to be called like getSales(). Anyway, I think your problem is related to this.

To rephrase:
getSales is a function, and inside that function you have a local variable called getSales. You can't access that local variable from outside that function (I'm assuming this is true for VB), so every time you invoke getSales you are calling the entire function. (If I'm understanding this correctly). If you look, your code calls getSales 4 times, so you get asked the same question 4 times.

This post was edited by Azrad on Oct 21 2013 01:51pm
Member
Posts: 2,127
Joined: May 22 2011
Gold: 0.00
Oct 21 2013 03:45pm
I finally got it with all your guy's help. Azrad I will def be sending you some FG right now for the help. I appreciate it. I'm going to school for Networking, not programming thank god lol.

Code
Module Module1

Dim determineBonus As String
Dim determineDayOff As String
Dim getSales As Double
Dim sales As Double

Sub Main()
getSales = sales2()
determineBonus = cBonus(getSales)
determineDayOff = checkDayOff(getSales)
printInfo(getSales, determineBonus, determineDayOff)
End Sub

Function sales2()
Console.WriteLine("Please enter the sales for the month")
getSales = Console.ReadLine()
Return getSales
End Function

Function cBonus(ByRef getSales As Double)
Dim determineBonus As String = " "
If getSales >= 102500 Then
determineBonus = "You earned a bonus this month"
End If
If getSales < 102500 Then
determineBonus = "Sorry no bonus for the month"
End If
Return determineBonus
End Function

Function checkDayOff(ByRef getSales As Double)
Dim determineDayOff As String = " "
If getSales >= 112500 Then
determineDayOff = "All employees get a day off!"
Else
determineDayOff = "Sorry no earned day off"
End If
Return determineDayOff
End Function

Sub printInfo(ByRef getSales As Double, ByRef determineBonus As String, ByRef determineDayOff As String)
Console.WriteLine("Your sales for the month was $" & getSales)
Console.WriteLine("Earned the monthly bonus? " & determineBonus)
Console.WriteLine("Earned day off? " & determineDayOff)
End Sub


End Module
Go Back To Homework Help Topic List
Add Reply New Topic New Poll