|
-
Dec 14th, 2011, 11:09 PM
#1
Thread Starter
New Member
[RESOLVED] Nee help with code
I am new to coding, I am also having a serious issue with finishing this project. Could I please get some help.
the Galaxy Hotel asks you to write a Windows application that computes the occupancy rate of the hotel. Occupancy rate is a percentage that is equal to the number of rooms sold divided by the total number of rooms available. The hotel has seven floors. tThe user should use an Input Box function to respond to two questions about each floor: How many rooms are occupied on that floor? How many rooms on the floor are vacant? Display which floor you are asking about in each question. Display how many rooms are occupied and vacant on each floor in a List Box object. After the user has entered all the information, display the following results: the total number of rooms at the hotel, the number of occupied rooms, and the number of vacant rooms. Also display the occupancy rate as a percentage, such as 61%. Non-numeric values should not be accepted. Do not accept negative numbers. Publish the application after testing.
so far i have this for my code:
vb.net Code:
Public Class frmHotelOccupancy
Private Sub btnOccupancyInformation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOccupancyInformation.Click
' The btnOccupancyInformation click event accepts and displays up to thirty rooms
' from the user, and then calculates and displays the % of occupancy.
' Declare and Initialze variables
Dim decOccupiedRooms As Decimal
Dim strOccupiedRooms As String
Dim decTotalRooms As Decimal = 10
Dim strTotalRooms As String = CStr(0)
Dim intTotalRooms As Integer = 0
Dim intTotalOccupied As Integer = 0
Dim intTotalVacant As Integer = 0
Dim intVacant As Integer = 0
Dim decOccupancyRate As Decimal
Dim strInputMessage As String = "Enter # of occupied rooms"
Dim strInputHeading As String = "Occupancy Percent"
Dim strNormalMessage As String = "Enter # of occupied rooms"
Dim strNonNumericError As String = "ERROR - Enter a # of rooms occupied"
Dim strNegativeError As String = "ERROR - Enter a positive # of occupied rooms"
Dim intFloor As Integer
For intFloor = 1 To 7
Next
' Declare and intialize loop variables
Dim strCancelClick As String = ""
Dim intMaxNumberOfEntries As Integer = 6
Dim intMinNumberOfEntries As Integer = 0
' This loop allows the user to enter the room information (vacany or occupied)
' up to 10 rooms, and 7 floors. The loop terminates when the user has entered
' 10 rooms per 7 floors or clicks the Cancel button or the Close button in the InputBox.
strOccupiedRooms = InputBox(strInputMessage & intTotalOccupied, strInputHeading, " ")
Do Until intTotalOccupied > intMaxNumberOfEntries Or strOccupiedRooms = strCancelClick
If IsNumeric(strTotalRooms) Then
decOccupiedRooms = Convert.ToDecimal(strOccupiedRooms)
If decOccupiedRooms > 0 Then
lstVacancyAndOccupancy.Items.Add(decOccupiedRooms)
decOccupiedRooms += decOccupancyRate
intTotalOccupied += 1
strInputMessage = strNormalMessage
Else
strInputMessage = strNegativeError
End If
Else
strInputMessage = strNonNumericError
End If
If intTotalOccupied <= intMaxNumberOfEntries Then
strTotalRooms = InputBox(strInputMessage & intTotalRooms, strInputHeading, " ")
End If
Loop
'Makes label visible
lblPercentage.Visible = True
' Calculate and display pecentage of occupied rooms
If intTotalOccupied > -1 Then
decOccupancyRate = decOccupiedRooms / (decTotalRooms)
lblPercentage.Text = "Percentage of rooms occupied " & _
decOccupancyRate.ToString("F1") & "%"
Else
lblPercentage.Text = "No room occupancy entered"
End If
'Display the Enter Room Information button
btnOccupancyInformation.Enabled = False
End Sub
Last edited by Hack; Dec 15th, 2011 at 06:51 AM.
Reason: Added Highlight Tags
-
Dec 15th, 2011, 06:52 AM
#2
Re: Nee help with code
Moved From The CodeBank (which is for sharing code rather than asking questions )
-
Dec 15th, 2011, 07:49 AM
#3
Re: Nee help with code
You might need to tell us what you need to help with, we are not here to do your homework for you. Point at something specific that is not working, giving unexpected results and we can tell you why and suggest what you need to be looking at to solve it.
-
Dec 15th, 2011, 08:27 AM
#4
Thread Starter
New Member
Re: Nee help with code
when i run this my the #'s i enter into my input box keep repeating. And my lbl on the bottom is showing fractions of a percent not whole percentage.
-
Dec 15th, 2011, 08:45 AM
#5
Re: Nee help with code
 Originally Posted by goodgod1500
when i run this my the #'s i enter into my input box keep repeating. .
Tell us an example of the data you are putting in. What keeps repeating, the text that is shown in the message, the value that is shown, the value that is extracted? You need to be specific, we can not see what you are doing!
 Originally Posted by goodgod1500
And my lbl on the bottom is showing fractions of a percent not whole percentage.
That is because you have asked it to. F1 = 1 decimal place. A percentage is part of a whole, so 50% should be 0.5. If you want to get the percent, you either have to multiple by 100, or just use the other format that exists (check here) which I will let you find, magically called .... percent .
-
Dec 15th, 2011, 09:46 AM
#6
Thread Starter
New Member
Re: Nee help with code
Heres the issue, I need to find a occupancy %, I have a total set # of rooms, I have an input box that I input my occupied rooms. What ever number I use first wil repeat untill loop ends. The inputbox will also not allow me to cancel the process.
I just want to ********, I do not want someone to finish my work I just want to get input on what I am doing wrong.
Thanks
-
Dec 15th, 2011, 10:41 AM
#7
Re: Nee help with code
I do not know what ******* was supposed to mean, but hopefully, it was something nice .
Getting back to your questions, likely it is the same problem causing all your issues, the first input box puts the data into a variable called 'strOccupiedRooms' however in the loop the next input puts the data into 'strTotalRooms'.
And here, you check one variable is a number, but then use the other.
Code:
If IsNumeric(strTotalRooms) Then
decOccupiedRooms = Convert.ToDecimal(strOccupiedRooms)
-
Dec 15th, 2011, 10:55 AM
#8
Thread Starter
New Member
Re: Nee help with code
the ******** was suppose to be ********, not sure why that changed.
Thank you for your help, I cannot beieve I didn't see that.
-
Dec 15th, 2011, 10:56 AM
#9
Thread Starter
New Member
Re: Nee help with code
******** = c l e a r i f y
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|