Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
11/7/2013 10:52:29 AM EDT
Ok so I'm still slowly chugging along in my quest to learn VB. I'm not asking for anyone to write my code but a few suggestions would be appreciated. This shit just really isn't sinking in yet. I think whats vexing me is the assignment calls for the use of select case statement which we haven't really gone over.

I need to write a program that will allow the user to enter the number of checks written and find out the bank's total charges for the month. The total charges are the bank fee of $15.00 plus the check fees based on this:

Less than 40 = 0.10 per check
40 - 59 = 0.08 per
60 -79 = 0.06 per
80 or more = 0.04 per

Here is the code for my last programming assignment (which I am to use as a guide for writing this one)

Sub Main()
     
       Dim strEnteredValue As String
       Dim intMile As Integer = 1760
       Dim intFurlong As Integer = 220
       Dim intRemainingYards As Integer
       Dim intTotalYards As Integer
       Dim intTotalFurlong As Integer

       Console.WriteLine("Enter the number of yards: ")
       strEnteredValue = Console.ReadLine()
       intTotalYards = CInt(strEnteredValue)

       Console.WriteLine()

       intMile = intTotalYards \ 1760
       intRemainingYards = intTotalYards Mod 1760
       intTotalFurlong = intRemainingYards \ intFurlong
       intRemainingYards = intRemainingYards Mod intFurlong

       Console.WriteLine("Number of miles = " & intMile)
       Console.WriteLine("Number of furlongs = " & intTotalFurlong)
       Console.WriteLine("Number of yards = " & intRemainingYards)

       Console.WriteLine()

       Console.WriteLine("Press ENTER key to close console")

       strEnteredValue = Console.ReadLine()

   End Sub



11/7/2013 11:16:45 AM EDT
[#1]
I have not done VB in a long time, and I'm sure someone smarter than me will come along, but it looks like IF statements should work just fine.

IF nbrOfChecks < 40 THEN
   totalCharges = nbrOfChecks * 0.08 + 15
ELSE IF ...

ETA: Of course, you said you need to use a case statement.  Sorry.

See the example here.  Think of CASE a more efficient alternative to multiple IF statements.
11/7/2013 11:29:30 AM EDT
[#2]
Quote History
Quoted:ETA: Of course, you said you need to use a case statement.  Sorry.

See the example here.  Think of CASE a more efficient alternative to multiple IF statements.
View Quote


Actually I misspoke. It says I can use if, then, elself or select case statements.
11/7/2013 11:32:36 AM EDT
[#3]
I don't know VB, but the algorithm you're going to want is something like this.

Get number of check.
totalCost = $15.00

if(number < 40) then totalCost += (0.10 * number)
else if(number < 60) then totalCost += (0.08 * number)
else if(number < 80) then totalCost += (0.06 * number)
else totalCost += (0.04 * number)


What matters is that you understand what you're writing.  Let me know if you have any questions.

Edit: For SELECT, it looks like you could do this.

Select Case number
   Case 1 To 39
        totalCost += (0.10 * number)
   Case 40 to 59
       totalCost += (0.08 * number)
   Case 60 To 79
       totalCost += (0.06 * number)
   Case Else
       totalCost += (0.04 * number)
End Select
11/7/2013 11:32:51 AM EDT
[#4]
ETA:  Never mind.  Already answered and I didn't like doing homework anyway.