Results 1 to 9 of 9

Thread: [RESOLVED] Nee help with code

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    5

    Resolved [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:
    1. Public Class frmHotelOccupancy
    2.  
    3.     Private Sub btnOccupancyInformation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOccupancyInformation.Click
    4.         ' The btnOccupancyInformation click event accepts and displays up to thirty rooms
    5.         ' from the user, and then calculates and displays the % of occupancy.
    6.  
    7.         ' Declare and Initialze variables
    8.         Dim decOccupiedRooms As Decimal
    9.         Dim strOccupiedRooms As String
    10.         Dim decTotalRooms As Decimal = 10
    11.         Dim strTotalRooms As String = CStr(0)
    12.         Dim intTotalRooms As Integer = 0
    13.         Dim intTotalOccupied As Integer = 0
    14.         Dim intTotalVacant As Integer = 0
    15.         Dim intVacant As Integer = 0
    16.         Dim decOccupancyRate As Decimal
    17.         Dim strInputMessage As String = "Enter # of occupied rooms"
    18.         Dim strInputHeading As String = "Occupancy Percent"
    19.         Dim strNormalMessage As String = "Enter # of occupied rooms"
    20.         Dim strNonNumericError As String = "ERROR - Enter a # of rooms occupied"
    21.         Dim strNegativeError As String = "ERROR - Enter a positive # of occupied rooms"
    22.         Dim intFloor As Integer
    23.         For intFloor = 1 To 7
    24.            
    25.         Next
    26.  
    27.         ' Declare and intialize loop variables
    28.         Dim strCancelClick As String = ""
    29.         Dim intMaxNumberOfEntries As Integer = 6
    30.         Dim intMinNumberOfEntries As Integer = 0
    31.  
    32.         ' This loop allows the user to enter the room information (vacany or occupied)
    33.         ' up to 10 rooms, and 7 floors. The loop terminates when the user has entered
    34.         ' 10 rooms per 7 floors or clicks the Cancel button or the Close button in the InputBox.
    35.  
    36.         strOccupiedRooms = InputBox(strInputMessage & intTotalOccupied, strInputHeading, " ")
    37.  
    38.         Do Until intTotalOccupied > intMaxNumberOfEntries Or strOccupiedRooms = strCancelClick
    39.  
    40.             If IsNumeric(strTotalRooms) Then
    41.                 decOccupiedRooms = Convert.ToDecimal(strOccupiedRooms)
    42.                 If decOccupiedRooms > 0 Then
    43.                     lstVacancyAndOccupancy.Items.Add(decOccupiedRooms)
    44.                     decOccupiedRooms += decOccupancyRate
    45.                     intTotalOccupied += 1
    46.                     strInputMessage = strNormalMessage
    47.                 Else
    48.                     strInputMessage = strNegativeError
    49.                 End If
    50.             Else
    51.                 strInputMessage = strNonNumericError
    52.             End If
    53.  
    54.             If intTotalOccupied <= intMaxNumberOfEntries Then
    55.                 strTotalRooms = InputBox(strInputMessage & intTotalRooms, strInputHeading, " ")
    56.             End If
    57.  
    58.         Loop
    59.  
    60.         'Makes label visible
    61.         lblPercentage.Visible = True
    62.  
    63.         ' Calculate and display pecentage of occupied rooms
    64.         If intTotalOccupied > -1 Then
    65.             decOccupancyRate = decOccupiedRooms / (decTotalRooms)
    66.             lblPercentage.Text = "Percentage of rooms occupied " & _
    67.                 decOccupancyRate.ToString("F1") & "%"
    68.         Else
    69.             lblPercentage.Text = "No room occupancy entered"
    70.         End If
    71.  
    72.         'Display the Enter Room Information button
    73.         btnOccupancyInformation.Enabled = False
    74.  
    75.     End Sub
    Last edited by Hack; Dec 15th, 2011 at 06:51 AM. Reason: Added Highlight Tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Nee help with code

    Moved From The CodeBank (which is for sharing code rather than asking questions )

  3. #3
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    5

    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.

  5. #5
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Nee help with code

    Quote Originally Posted by goodgod1500 View Post
    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!

    Quote Originally Posted by goodgod1500 View Post
    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&#37; 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 .

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    5

    Re: Nee help with code

    Heres the issue, I need to find a occupancy &#37;, 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

  7. #7
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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)

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    5

    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.

  9. #9

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    5

    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
  •  



Click Here to Expand Forum to Full Width