| | |
Visual Basic 2008 programming challenges
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Mar 2009
Posts: 826
Reputation:
Solved Threads: 150
0
#2 23 Days Ago
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
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
If anyone has helped you solve your problem, please mark your thread as solved.
Thanks
Thanks
0
#3 20 Days Ago
Heres an example of nested loops that acheives what you are trying to do:
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.
VB.NET Syntax (Toggle Plain Text)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim TotalFilledRooms As Integer = 0 Dim perc As Double For i As Integer = 1 To 8 Dim response As Boolean = False Dim filledRooms As Integer While (Not response) Or (filledRooms < 0 Or filledRooms > 30) response = Integer.TryParse(InputBox("How many rooms on floor " & i.ToString() & " are occupied?", "Enter number of occupied rooms"), filledRooms) End While perc = Math.Round((filledRooms / 30) * 100, 1) TotalFilledRooms += filledRooms Dim floor As String = "Floor " & i.ToString() & ": " & filledRooms.ToString() & "/30 " & perc.ToString() & "%" lstFloors.Items.Add(floor) Next perc = Math.Round((TotalFilledRooms / 240) * 100, 1) lblOccRooms.Text = TotalFilledRooms.ToString() & "/240" lblOccPerc.Text = perc.ToString() & "%" End Sub
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.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
![]() |
Similar Threads
- visual basic ,Chapter 6, Programming Challenge 6: Travel Expenses, Page 408. (Visual Basic 4 / 5 / 6)
- Help, Reporting with Visual Basic 2008 Express (VB.NET)
- Edit registry in visual basic 2008 (VB.NET)
- How can i insert the tools in the toolbox of Visual Basic 2008 (VB.NET)
- Visual Basic 2008 and Access 2003 - Cant manage to search, can someone help ? (VB.NET)
- Visual basic programin 2008 (VB.NET)
- Visual Basic 2008 Express Edition Login System (VB.NET)
- Program to convert numbers into words in visual basic 2008 (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: Single Sided Id Card Printers
- Next Thread: Opening a new window form with web browser control,with webbrowser.navigating event
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account array basic beginner bing browser button buttons center check code crystalreport cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic dropdownlist excel fade file-dialog filter forms ftp generatetags google gridview html images input insert intel internet listview mobile monitor net networking objects open output panel passingparameters pdf picturebox port position print printing problem remove save searchbox searchvb.net select serial settings shutdown soap sqlserver survey table tcp temperature text textbox timer timespan toolbox transparency trim update user vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode year





