944,017 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 3163
  • VB.NET RSS
Nov 7th, 2009
-2

Visual Basic 2008 programming challenges

Expand Post »
Hello!

I currently am enrolled in an intro to VB2008. I have done well thus far but have hit a snag on Chapter 5 programming challenge 4 on p350 of the 4th edition(yellow). I swear to you I have put probably 10 hours into this embarressingly and I am ready to throw my laptop into the wall lol.
The "Hotel Occupancy" challenge states there are 8 floors, 30 rooms per floor. I am asked to design a program that prompts the user 8 separate times with an input box so they can enter the rooms that are filled on each floor.
The program should display in a listbox the floor #, rooms occupied on that floor, and percentage of rooms occupied on that floor.In addition to the list box, two labels on the form should display total occupancy percentage for entire hotel and total rooms occupied respectively.
I am new but familiar with loops and such but this one has got me. Any ideas a plus-Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dimonbak is offline Offline
1 posts
since Nov 2009
Nov 7th, 2009
0
Re: Visual Basic 2008 programming challenges
First, PM a mod and have this thread moved to the .NET forum since this is the "classic vb verision 4/5/6 and not versions for versions2002/2003/2005/2008/2010.

Then, there are several ways in which to solve this. A single do while result <> "" or eight of those (one for each floor) or even a recursive call to the proceedure that collects this information.



Good Luck
Reputation Points: 156
Solved Threads: 296
Posting Virtuoso
vb5prgrmr is offline Offline
1,670 posts
since Mar 2009
Nov 10th, 2009
0
Re: Visual Basic 2008 programming challenges
Heres an example of nested loops that acheives what you are trying to do:

VB.NET Syntax (Toggle Plain Text)
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3. Dim TotalFilledRooms As Integer = 0
  4. Dim perc As Double
  5.  
  6. For i As Integer = 1 To 8
  7. Dim response As Boolean = False
  8. Dim filledRooms As Integer
  9.  
  10. While (Not response) Or (filledRooms < 0 Or filledRooms > 30)
  11. response = Integer.TryParse(InputBox("How many rooms on floor " & i.ToString() & " are occupied?", "Enter number of occupied rooms"), filledRooms)
  12. End While
  13.  
  14. perc = Math.Round((filledRooms / 30) * 100, 1)
  15.  
  16. TotalFilledRooms += filledRooms
  17.  
  18. Dim floor As String = "Floor " & i.ToString() & ": " & filledRooms.ToString() & "/30 " & perc.ToString() & "%"
  19. lstFloors.Items.Add(floor)
  20. Next
  21.  
  22. perc = Math.Round((TotalFilledRooms / 240) * 100, 1)
  23. lblOccRooms.Text = TotalFilledRooms.ToString() & "/240"
  24. lblOccPerc.Text = perc.ToString() & "%"
  25.  
  26. End Sub
The for loop ensures that 8 values are requested.
Theres some basic validation in the while loop, if the returned value cannot be parsed as an integer or the integer returned is outside the range 0-30 then the input window will reappear until a valid value is entered.
Reputation Points: 512
Solved Threads: 246
Nearly a Posting Virtuoso
Ryshad is offline Offline
1,260 posts
since Aug 2009
Jun 15th, 2010
0

Simple Loan Calculator using a Loop

What Am I missing to get this to calculate 563.00 loan, 1% interest, 5 monthly payments of 116.00?

[private Sub btnDisplayBal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayBal.Click
Dim Payment As Double = 116
Dim LoanAmt As Double = 563
Dim InterestRt As Double = 0.01
Dim BalDue As Double
Dim AmtOwed As Double
Dim fmtStr As String = "{0,2}{4,10}"

lstboxBal.Items.Clear()
'Figure out how to do the math for the Intrs Rate and Mthly pymt
'Minus total loan amount to get balance dsplyd for nxt 5 mths
'I need a loop to show current balance after payment + interest
'I need 2 columns month and current balance
For Month As Integer = 1 To 5
AmtOwed = Payment * InterestRt
BalDue = Payment - LoanAmt
lstboxBal.Items.Add(BalDue)
Next

End Sub
End Class]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Moorendeavors is offline Offline
1 posts
since Jun 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Setting up a dialog box (font & color)
Next Thread in VB.NET Forum Timeline: For Loop Over For Each Loop Issue





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC