Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Calculations Help!

Calculations Help!

Scheduled Pinned Locked Moved Visual Basic
helpquestion
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10694570
    wrote on last edited by
    #1

    I am writing a code for my CIS-115 class. I have all of the information that I need in it (I think!), but I cannot get ALL of my calculations to execute correctly; only 2 of 5 come out right. Am I allowed to post it here to get help?

    D 1 Reply Last reply
    0
    • U User 10694570

      I am writing a code for my CIS-115 class. I have all of the information that I need in it (I think!), but I cannot get ALL of my calculations to execute correctly; only 2 of 5 come out right. Am I allowed to post it here to get help?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Yes, but don't ask for anyone to write your code for you. That's the restriction.

      A guide to posting questions on CodeProject

      How to debug small programs
      Dave Kreskowiak

      U 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Yes, but don't ask for anyone to write your code for you. That's the restriction.

        A guide to posting questions on CodeProject

        How to debug small programs
        Dave Kreskowiak

        U Offline
        U Offline
        User 10694570
        wrote on last edited by
        #3

        You will need to design an application that will receive the customer type and its units of utility used for the billing duration. The application will calculate and display the cost per unit based on the customer type and the total charges for that billing cycle. Calculate the charges using the following data. Customer Type Units Consumed Cost per unit ($) Commercial <= 1,000 $0.50 per unit Commercial 1,000 < $0.50 per unit Industrial < 800 $0.65 per unit Industrial 800 <= 2,000 $0.55 per unit Industrial 2,000 < $0.50 per unit Residential < 500 $0.85 per unit Residential 500 <= $0.75 per unit Make sure that the units consumed entered is a positive number and the customer Type is valid; otherwise your program should display an error message and ask for the data to be entered again until the user enters valid data. Test your algorithm with the following three sets of data. Test case 1: Units used of 799, Customer Type is Industrial Test case 2: Units used 500, Customer Type is Residential Test case 3: Units used 800, Customer Type is Industrial Test case 4: Units used 1000, Customer Type is Commercial Test case 5: Units used 499, Customer Type is Residential

        U 1 Reply Last reply
        0
        • U User 10694570

          You will need to design an application that will receive the customer type and its units of utility used for the billing duration. The application will calculate and display the cost per unit based on the customer type and the total charges for that billing cycle. Calculate the charges using the following data. Customer Type Units Consumed Cost per unit ($) Commercial <= 1,000 $0.50 per unit Commercial 1,000 < $0.50 per unit Industrial < 800 $0.65 per unit Industrial 800 <= 2,000 $0.55 per unit Industrial 2,000 < $0.50 per unit Residential < 500 $0.85 per unit Residential 500 <= $0.75 per unit Make sure that the units consumed entered is a positive number and the customer Type is valid; otherwise your program should display an error message and ask for the data to be entered again until the user enters valid data. Test your algorithm with the following three sets of data. Test case 1: Units used of 799, Customer Type is Industrial Test case 2: Units used 500, Customer Type is Residential Test case 3: Units used 800, Customer Type is Industrial Test case 4: Units used 1000, Customer Type is Commercial Test case 5: Units used 499, Customer Type is Residential

          U Offline
          U Offline
          User 10694570
          wrote on last edited by
          #4

          Sub Main()
          Dim customerType As String
          Dim unitsConsumed As Decimal = 0
          Dim costPerUnit As Decimal = 0
          Dim totalCharges As Decimal = 0
          Do
          Console.Write("Enter the customer type as commercial, industrial, or residential: ")
          customerType = Console.ReadLine()
          While customerType <> "commercial" And customerType <> "industrial" And customerType <> "residential"
          Console.WriteLine("ERROR - Enter commerical, industrial, or residential.")
          Console.Write("Enter the customer type as commercial, industrial, or residential: ")
          customerType = Console.ReadLine()
          End While
          Console.Write("Enter the units consumed: ")
          unitsConsumed = Console.ReadLine()
          While unitsConsumed < 0
          Console.WriteLine("ERROR - Please enter a value greater than zero.")
          Console.Write("Enter the units consumed. ")
          unitsConsumed = Console.ReadLine()
          End While
          If unitsConsumed <= 1000 Then
          costPerUnit = 0.5
          If unitsConsumed < 1000 Then
          costPerUnit = 0.5
          If unitsConsumed < 800 Then
          costPerUnit = 0.65
          If (unitsConsumed > 800) And (unitsConsumed <= 2000) Then
          costPerUnit = 0.55
          If unitsConsumed > 2000 Then
          costPerUnit = 0.5
          If unitsConsumed < 500 Then
          costPerUnit = 0.85
          If unitsConsumed >= 500 Then
          costPerUnit = 0.75
          End If
          End If
          End If
          End If
          End If
          End If
          End If
          totalCharges = unitsConsumed * costPerUnit
          Console.WriteLine("The total charges are: " & totalCharges)
          Console.ReadLine()
          Loop
          End Sub

          U M L Z 4 Replies Last reply
          0
          • U User 10694570

            Sub Main()
            Dim customerType As String
            Dim unitsConsumed As Decimal = 0
            Dim costPerUnit As Decimal = 0
            Dim totalCharges As Decimal = 0
            Do
            Console.Write("Enter the customer type as commercial, industrial, or residential: ")
            customerType = Console.ReadLine()
            While customerType <> "commercial" And customerType <> "industrial" And customerType <> "residential"
            Console.WriteLine("ERROR - Enter commerical, industrial, or residential.")
            Console.Write("Enter the customer type as commercial, industrial, or residential: ")
            customerType = Console.ReadLine()
            End While
            Console.Write("Enter the units consumed: ")
            unitsConsumed = Console.ReadLine()
            While unitsConsumed < 0
            Console.WriteLine("ERROR - Please enter a value greater than zero.")
            Console.Write("Enter the units consumed. ")
            unitsConsumed = Console.ReadLine()
            End While
            If unitsConsumed <= 1000 Then
            costPerUnit = 0.5
            If unitsConsumed < 1000 Then
            costPerUnit = 0.5
            If unitsConsumed < 800 Then
            costPerUnit = 0.65
            If (unitsConsumed > 800) And (unitsConsumed <= 2000) Then
            costPerUnit = 0.55
            If unitsConsumed > 2000 Then
            costPerUnit = 0.5
            If unitsConsumed < 500 Then
            costPerUnit = 0.85
            If unitsConsumed >= 500 Then
            costPerUnit = 0.75
            End If
            End If
            End If
            End If
            End If
            End If
            End If
            totalCharges = unitsConsumed * costPerUnit
            Console.WriteLine("The total charges are: " & totalCharges)
            Console.ReadLine()
            Loop
            End Sub

            U Offline
            U Offline
            User 10694570
            wrote on last edited by
            #5

            This is the code that I have, but only Test Case 1 and 4 execute correctly. I have sat here for hours looking through my book and lectures, but I'm just blind to my problem. Thank you, in advance, if you are able to help me!

            1 Reply Last reply
            0
            • U User 10694570

              Sub Main()
              Dim customerType As String
              Dim unitsConsumed As Decimal = 0
              Dim costPerUnit As Decimal = 0
              Dim totalCharges As Decimal = 0
              Do
              Console.Write("Enter the customer type as commercial, industrial, or residential: ")
              customerType = Console.ReadLine()
              While customerType <> "commercial" And customerType <> "industrial" And customerType <> "residential"
              Console.WriteLine("ERROR - Enter commerical, industrial, or residential.")
              Console.Write("Enter the customer type as commercial, industrial, or residential: ")
              customerType = Console.ReadLine()
              End While
              Console.Write("Enter the units consumed: ")
              unitsConsumed = Console.ReadLine()
              While unitsConsumed < 0
              Console.WriteLine("ERROR - Please enter a value greater than zero.")
              Console.Write("Enter the units consumed. ")
              unitsConsumed = Console.ReadLine()
              End While
              If unitsConsumed <= 1000 Then
              costPerUnit = 0.5
              If unitsConsumed < 1000 Then
              costPerUnit = 0.5
              If unitsConsumed < 800 Then
              costPerUnit = 0.65
              If (unitsConsumed > 800) And (unitsConsumed <= 2000) Then
              costPerUnit = 0.55
              If unitsConsumed > 2000 Then
              costPerUnit = 0.5
              If unitsConsumed < 500 Then
              costPerUnit = 0.85
              If unitsConsumed >= 500 Then
              costPerUnit = 0.75
              End If
              End If
              End If
              End If
              End If
              End If
              End If
              totalCharges = unitsConsumed * costPerUnit
              Console.WriteLine("The total charges are: " & totalCharges)
              Console.ReadLine()
              Loop
              End Sub

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              Look at your nested if statement 100 meets these criteria 1000, 1000, 800 500 so which value will be returned, the first of course.

              Never underestimate the power of human stupidity RAH

              1 Reply Last reply
              0
              • U User 10694570

                Sub Main()
                Dim customerType As String
                Dim unitsConsumed As Decimal = 0
                Dim costPerUnit As Decimal = 0
                Dim totalCharges As Decimal = 0
                Do
                Console.Write("Enter the customer type as commercial, industrial, or residential: ")
                customerType = Console.ReadLine()
                While customerType <> "commercial" And customerType <> "industrial" And customerType <> "residential"
                Console.WriteLine("ERROR - Enter commerical, industrial, or residential.")
                Console.Write("Enter the customer type as commercial, industrial, or residential: ")
                customerType = Console.ReadLine()
                End While
                Console.Write("Enter the units consumed: ")
                unitsConsumed = Console.ReadLine()
                While unitsConsumed < 0
                Console.WriteLine("ERROR - Please enter a value greater than zero.")
                Console.Write("Enter the units consumed. ")
                unitsConsumed = Console.ReadLine()
                End While
                If unitsConsumed <= 1000 Then
                costPerUnit = 0.5
                If unitsConsumed < 1000 Then
                costPerUnit = 0.5
                If unitsConsumed < 800 Then
                costPerUnit = 0.65
                If (unitsConsumed > 800) And (unitsConsumed <= 2000) Then
                costPerUnit = 0.55
                If unitsConsumed > 2000 Then
                costPerUnit = 0.5
                If unitsConsumed < 500 Then
                costPerUnit = 0.85
                If unitsConsumed >= 500 Then
                costPerUnit = 0.75
                End If
                End If
                End If
                End If
                End If
                End If
                End If
                totalCharges = unitsConsumed * costPerUnit
                Console.WriteLine("The total charges are: " & totalCharges)
                Console.ReadLine()
                Loop
                End Sub

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Another day, another hint.

                If x < 1000 Then
                If x < 800 Then
                If x > 2000 Then
                ' when does this line get evaluated?
                ' A: if x < 1000 AND x < 800 AND x > 2000
                End If
                End If
                End If

                Find me a number smaller than 1000, but larger than 2000. There's another problem, take a look at the example-rules;

                Member 10728667 wrote:

                Commercial <= 1,000 $0.50 per unit Commercial 1,000 < $0.50 per unit

                If think the first price is for commercial stuff if you buy 1000 items or less, and the second price would be if you buy MORE than 1000 items. That's prolly what the position of the operator should imply. Back to the code;

                If unitsConsumed <= 1000 Then
                costPerUnit = 0.5
                If unitsConsumed > 1000 Then

                Now that I switched the operator to what it probably should be, does it help to diagnose the error?

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                1 Reply Last reply
                0
                • U User 10694570

                  Sub Main()
                  Dim customerType As String
                  Dim unitsConsumed As Decimal = 0
                  Dim costPerUnit As Decimal = 0
                  Dim totalCharges As Decimal = 0
                  Do
                  Console.Write("Enter the customer type as commercial, industrial, or residential: ")
                  customerType = Console.ReadLine()
                  While customerType <> "commercial" And customerType <> "industrial" And customerType <> "residential"
                  Console.WriteLine("ERROR - Enter commerical, industrial, or residential.")
                  Console.Write("Enter the customer type as commercial, industrial, or residential: ")
                  customerType = Console.ReadLine()
                  End While
                  Console.Write("Enter the units consumed: ")
                  unitsConsumed = Console.ReadLine()
                  While unitsConsumed < 0
                  Console.WriteLine("ERROR - Please enter a value greater than zero.")
                  Console.Write("Enter the units consumed. ")
                  unitsConsumed = Console.ReadLine()
                  End While
                  If unitsConsumed <= 1000 Then
                  costPerUnit = 0.5
                  If unitsConsumed < 1000 Then
                  costPerUnit = 0.5
                  If unitsConsumed < 800 Then
                  costPerUnit = 0.65
                  If (unitsConsumed > 800) And (unitsConsumed <= 2000) Then
                  costPerUnit = 0.55
                  If unitsConsumed > 2000 Then
                  costPerUnit = 0.5
                  If unitsConsumed < 500 Then
                  costPerUnit = 0.85
                  If unitsConsumed >= 500 Then
                  costPerUnit = 0.75
                  End If
                  End If
                  End If
                  End If
                  End If
                  End If
                  End If
                  totalCharges = unitsConsumed * costPerUnit
                  Console.WriteLine("The total charges are: " & totalCharges)
                  Console.ReadLine()
                  Loop
                  End Sub

                  Z Offline
                  Z Offline
                  ZurdoDev
                  wrote on last edited by
                  #8

                  The easy thing to do is put a breakpoint and then step through your code and you'll see exactly what is happening. It should be very easy to solve at that point.

                  There are only 10 types of people in the world, those who understand binary and those who don't.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups