i'm new to visual basic and I managed to make somewhat of an assignment I need. now it's not perfect but, I am terrible when it comes to calculations... what am I doing wrong? ;-;

' This procedure calculates and displays each floors
' occupancy rate.

Dim intCount As Integer ' Loop counter
Dim decoccupancy As Decimal ' occupancy rate

' Calculate the occupancy rate for each floor, the total
' of all occupancy rates , and the total rooms occupied.

For intCount = 0 To intMAX_floor = 250
decoccupancy = introoms(intCount) * decroom_occupancy_RATE
decoccupancyrate(intCount) = decoccupancy
decTotaloccupancyrate /= decoccupancy
intTotalrooms &= Int(intCount)

it's telling me to divie the number of rooms by the occupied rooms... 18/30 = .6 or 60%
and the hotel has 240 rooms

Not sure wat direction to go in now.... Thanks

this is what i have so far can someone help pelaseee?

Public Class Form1

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click


        Me.Close()
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

        'This procedure clears all labels and list box.

        ListBox1.Items.Clear()
        lblOccupancyRate.Text = String.Empty
        lblTotalRooms.Text = String.Empty

    End Sub

    Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click

        
        'This calculates and displays each floors occupancy rate.
        Dim decOccupancy As Array
        Dim decTotalOccupancyRate As Decimal
        Dim strUserInput As String
        Dim decTotalOccupancy As Decimal
        Dim intCount As Integer
        'ListBox1.Items.Add

        'Calculate the occupancy rate for each floor, the total of all occupancy rates, and the total rooms occupied.
        For intCount As Integer = 0 To 7
     strUserInput = InputBox("Enter the number of rooms occupied. Provide a value")
            decOccupancy(intCount) = CDec(strUserInput) / 30
            ListBox1.Items.Add(decOccupancy(intCount))
            decTotalOccupancy += CDec(strUserInput)
        Next
        Do
            ListBox1.Items.Add(decTotalOccupancy)
            ListBox1.Items.Add(decTotalOccupancy / 240)
        Loop

        If CInt(strUserInput) > 30 Then
            MessageBox.Show("Please enter a number greater than 0 and less than 30")
        End If

        'Display the running total.
        lblOccupancyRate.Text = decTotalOccupancyRate.ToString("c")

The hotel has 8 floors and 30 rooms on each floor. Create an application that calculates the occupancy rate for each floor, and the overall occupancy rate for the hotel. The occupancy rate is the percentage of rooms occupied, and may be calculated by dividing the number of rooms occupied by the number of rooms.
When the user clicks the "Complete Report" button, a loop should execute and iterate 8 times. Each time the loop iterates, it should display an input box for one of the hotel's floors. The input box should ask the user to enter the number of rooms occupied on that floor. As the user enters a value for each floor, the loop should calculate the occupancy rate for that floor, and display the information for that floor in the list box. When the number of occupied rooms has been entered for all the floors, the application should display the total number of rooms occupied and the overall occupnacy rate of the hotel.

1. You can't add rates, it just doesn't work
2. When you display percentages, multiply by 100
3. You are processing and THEN checking for user errors and doing nothing about it.
Instead force them to get it right before going on.
4. Don't assume the user entered correct data
5. Keeping track of the occupancy per floor makes more sense than the rate

How about this? (Used notepad so it may be a bit weird.):

'This calculates and displays each floors occupancy rate.
        Dim Occupancy(7) As Byte 'Why do you have an array that is going to be dropped
        Dim TotOccupancy As Byte = 0 '240 is < 255 - can't overflow
       Dim decOccupancyRate As Decimal
        Dim strUserInput As String
        Dim decOccupancy As Decimal
        Dim intCount As Byte
        Dim RoomCount As Integer 'User can say 2 billion and shouldn't overflow
        'ListBox1.Items.Add

   For intCount As Integer = 0 To 7
      RoomCount = 0
      while RoomCount < 1 or RoomCount > 30
         strUserInput = InputBox("Enter the number of rooms occupied. Provide a value")
         if isnumeric(strUserInput) then RoomCount = strUserInput 
         if RoomCount < 1 or RoomCount > 30 then
            MessageBox.Show("Please enter a number greater than 0 and less than 30")
         End If
      end while
      Occupancy(intCount) = RoomCount 
      TotOccupancy += RoomCount 
      decOccupancyRate = CDec(RoomCount) / 30.
      ListBox1.Items.Add(decOccupancyRate*100)
   Next
   strUserInput = "Total occupancy= " & TotOccupancy.ToString()
   ListBox1.Items.Add(strUserInput)
   decOccupancyRate = CDec(TotOccupancy) / 240.
   ListBox1.Items.Add(decOccupancyRate * 100)

bah its not working...thing is i dont thing we r suppose to use bytes in this assignment...im so frustrated right now... Main problem now is cant to string to Integer and Byte to integer... Could i use Double insetad of byte? thign part where i cant String to integar is bolded

'This calculates and displays each floors occupancy rate.
        Dim Occupancy(7) As Byte 'Why do you have an array that is going to be dropped
        Dim TotOccupancy As Byte = 0 '240 is < 255 - can't overflow
        Dim decOccupancyRate As Decimal
        Dim strUserInput As String
        Dim decOccupancy As Decimal
        Dim Count As Byte
        Dim RoomCount As Integer 'User can say 2 billion and shouldn't overflow
        'ListBox1.Items.Add

        For intCount As Integer = 0 To 7
            RoomCount = 0
            While RoomCount < 1 Or RoomCount > 30
                strUserInput = InputBox("Enter the number of rooms occupied. Provide a value")
                If IsNumeric(strUserInput) Then [B]RoomCount = strUserInput[/B]
                If RoomCount < 1 Or RoomCount > 30 Then
                    MessageBox.Show("Please enter a number greater than 0 and less than 30")
                End If
            End While
            Occupancy(intCount) = RoomCount
            TotOccupancy += RoomCount
            decOccupancyRate = CDec(RoomCount) / 30
            ListBox1.Items.Add(decOccupancyRate * 100)
        Next
        strUserInput = "Total occupancy= " & TotOccupancy.ToString()
        ListBox1.Items.Add(strUserInput)
        decOccupancyRate = CDec(TotOccupancy) / 240
        ListBox1.Items.Add(decOccupancyRate * 100)

Edited 7 Years Ago by hhh0505: n/a

Hmmm, works for me. 'Course I did say it was from notepad

'This calculates and displays each floors occupancy rate.        
        Dim Occupancy(7) As Byte 'Why do you have an array that is going to be dropped        
        Dim TotOccupancy As Byte = 0 '240 is < 255 - can't overflow       
        Dim decOccupancyRate As Decimal
        Dim strUserInput As String
        Dim decOccupancy As Decimal
        Dim intCount As Byte
        Dim RoomCount As Integer 'User can say 2 billion and shouldn't overflow        
        'ListBox1.Items.Add    
        For intCount = 0 To 7
            RoomCount = -1
            While RoomCount < 0 Or RoomCount > 30
                strUserInput = InputBox("Enter the number of rooms occupied. Provide a value")
                If IsNumeric(strUserInput) Then RoomCount = strUserInput
                If RoomCount < 0 Or RoomCount > 30 Then
                    MessageBox.Show("Please enter a number >= 0 and <= 30")
                End If
            End While
            Occupancy(intCount) = RoomCount
            TotOccupancy += RoomCount
            decOccupancyRate = CDec(RoomCount) / 30.0
            ListBox1.Items.Add(decOccupancyRate * 100)
        Next
        strUserInput = "Total occupancy= " & TotOccupancy.ToString()
        ListBox1.Items.Add(strUserInput)
        decOccupancyRate = CDec(TotOccupancy) / 240.0
        ListBox1.Items.Add(decOccupancyRate * 100)

yea i think im scerwed lo. thanks for the help... still not working

Hmmm, works for me. 'Course I did say it was from notepad

'This calculates and displays each floors occupancy rate.        
        Dim Occupancy(7) As Byte 'Why do you have an array that is going to be dropped        
        Dim TotOccupancy As Byte = 0 '240 is < 255 - can't overflow       
        Dim decOccupancyRate As Decimal
        Dim strUserInput As String
        Dim decOccupancy As Decimal
        Dim intCount As Byte
        Dim RoomCount As Integer 'User can say 2 billion and shouldn't overflow        
        'ListBox1.Items.Add    
        For intCount = 0 To 7
            RoomCount = -1
            While RoomCount < 0 Or RoomCount > 30
                strUserInput = InputBox("Enter the number of rooms occupied. Provide a value")
                If IsNumeric(strUserInput) Then RoomCount = strUserInput
                If RoomCount < 0 Or RoomCount > 30 Then
                    MessageBox.Show("Please enter a number >= 0 and <= 30")
                End If
            End While
            Occupancy(intCount) = RoomCount
            TotOccupancy += RoomCount
            decOccupancyRate = CDec(RoomCount) / 30.0
            ListBox1.Items.Add(decOccupancyRate * 100)
        Next
        strUserInput = "Total occupancy= " & TotOccupancy.ToString()
        ListBox1.Items.Add(strUserInput)
        decOccupancyRate = CDec(TotOccupancy) / 240.0
        ListBox1.Items.Add(decOccupancyRate * 100)

Basically i have a listbox and the user should be prompetd to enter a value for each floor... 1-8 and you have to give a value for the amount of rooms occupied... then it displays it on the listbox once the loop in complete ...can someoen pelase help me with this code? im really close...

'This calculates and displays each floors occupancy rate.        
        Dim intOccupancy(7) As Integer
        Dim intTotOccupancy As Integer = 0
        Dim decOccupancyRate As Decimal
        Dim strUserInput As String
        Dim decOccupancy As Decimal
        Dim intCount As Byte
        Dim intRoomCount As Integer 'User can say 2 billion and shouldn't overflow        
        'ListBox1.Items.Add    
        For intCount = 0 To 7
            intRoomCount = -1
            While intRoomCount < 0 Or intRoomCount > 30
                strUserInput = InputBox("Enter the number of rooms occupied. Provide a value")
                If IsNumeric(strUserInput) Then intRoomCount = strUserInput
                If intRoomCount < 0 Or intRoomCount > 30 Then
                    MessageBox.Show("Please enter a number >= 0 and <= 30")
                End If
            End While
            intOccupancy(intCount) = intRoomCount
            intTotOccupancy += intRoomCount
            decOccupancyRate = CDec(intRoomCount) / 30
            ListBox1.Items.Add(decOccupancyRate * 100)
        Next
        strUserInput = "Total occupancy= " & intTotOccupancy.ToString()
        ListBox1.Items.Add(strUserInput)
        decOccupancyRate = CDec(CDec(intTotOccupancy) / 240.0)
        ListBox1.Items.Add(decOccupancyRate * 100)
This article has been dead for over six months. Start a new discussion instead.