2 Replies - 1185 Views - Last Post: 08 May 2014 - 01:38 PM Rate Topic: -----

#1 Painkiller7   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-May 14

VB 2012 - Assignment help!

Posted 08 May 2014 - 12:51 PM

Hi guys,

Im a newb and need help with this assignment.

I am having two issues with my code:
1 - I cant figure out how to cut off the decimal at 2 decimal spots. I googled, but I keep finding answers regarding rounding up. I do not want to round up. Just stop at 2 decimal places.
2 - the totals dont seem to be displaying in the proper labels. Am I missing a line of code somewhere?

Please help!

This is what my result looks like:
Posted Image

This is what it is supposed to look like:
Posted Image

This is my current code:
Public Class Form1

    Private Sub btnComplete_Click(sender As Object, e As EventArgs) Handles btnComplete.Click
        'This calculates and displays each floors occupancy rate. 
        Const MAX_FLOOR As Integer = 8
        Const ROOMS_PER_FLOOR As Integer = 30
        Dim occupancy As Integer         ' Occupancy count 
        Dim occupancySum As Integer = 0  ' Total Occupancy count 

        ' Calculate the occupancy rate for each floor, the total of all occupancy rates, and the total rooms occupied. 
        lstOutput.Items.Clear()
        For Floor As Integer = 1 To MAX_FLOOR
            occupancy = CInt(InputBox("Please enter the number of rooms" & vbCrLf & "occupied on floor " & Floor))
            occupancySum += occupancy
            lstOutput.Items.Add("Floor: " & Floor & " Rooms Occupied: " & occupancy & " Occupancy Rate: " & (occupancy / ROOMS_PER_FLOOR) * 100 & "%")
        Next

        lstOutput.Items.Add("Total occupancy is " & occupancySum & " rooms - " & (occupancySum / (ROOMS_PER_FLOOR * MAX_FLOOR)) * 100 & "% full.")

    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        'This procedure clears all labels and list box. 
        lstOutput.Items.Clear()
        lblOccupancyRate.Text = String.Empty
        lblTotalOccupied.Text = String.Empty

    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        'This exits the application. 
        Me.Close()

    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: VB 2012 - Assignment help!

#2 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2683
  • View blog
  • Posts: 10,740
  • Joined: 03-December 12

Re: VB 2012 - Assignment help!

Posted 08 May 2014 - 01:05 PM

Do your math by itself and add the individual values to variables . Then use. .toString(n2) to add two decimal places.

Check the names of your labels. You may have misnamed them or moved them to another spot.
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1730
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: VB 2012 - Assignment help!

Posted 08 May 2014 - 01:38 PM

I don't see anywhere in your code where you're assigning anything to a text property of a label.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1