locked
Rooftop Garden RRS feed

  • Question

  • This code is hurting my brain. I can't seem to figure out why the Totals are the same in the end. It's clearly taking the inputs from the last set of number(WITH). How can I fix this?

    '-----------------'
    Start()
    GetWithout()
    GetWith()
    GetTotalWithout()
    GetTotalWith()
    GetSavings()
    Savings()
    '------------------'
    Sub Start
    TextWindow.WriteLine("What is the name of your business?")
    name = TextWindow.Read()
    TextWindow.WriteLine("What do you project the annual savings to be?")
    annual = TextWindow.ReadNumber()
    TextWindow.WriteLine("--------------")
    EndSub

    Sub GetWithout
      TextWindow.WriteLine("Enter the energy bills WITHOUT the rooftop garden:")
        Months()
    EndSub
        

    Sub GetWith
      TextWindow.WriteLine("------------")
      TextWindow.WriteLine("Enter the energy bills WITH the rooftop garden:")
      Months() 
    EndSub

    Sub Months
      Month = "1=Janurary;2=Feburary;3=March;4=April;5=May;6=June;7=July;8=August;9=September;10=October;11=November;12=December"
      count=1
    While count <= 12 
      TextWindow.Write(month[count]+": ")
      bills[count]=textwindow.Read()
      count=count+1
    EndWhile
    TextWindow.WriteLine("")
    TextWindow.WriteLine("Here is what was entered")
    For count= 1 To 12
      TextWindow.WriteLine(month[count]+": "+bills[count])
    EndFor
    EndSub


      Sub GetTotalWithout
      'SUM is for total WITHOUT
      total = 0
      For i = 1 To  Array.GetItemCount(bills)
        total = total + bills[i]  
      EndFor
      TextWindow.WriteLine("--------------")
      TextWindow.WriteLine("Your total WITHOUT is: " + total)
    EndSub


    Sub GetTotalWith
      'sums is for the total WITH
      total1 = 0
      For i = 1 To Array.GetItemCount(bills)
        total1 = total1 + bills[i]
      EndFor
      TextWindow.WriteLine("Your total WITH is: " + total1)
      endsub
      
      Sub GetSavings
        savings = 0
        savings = total - total1
        TextWindow.WriteLine("Your total Savings are:"  + savings)
        EndSub
      
      Sub Savings
        difference = 0
        difference = savings-annual
        TextWindow.WriteLine("")
        TextWindow.WriteLine("Actual Savings: " + savings)
        TextWindow.WriteLine("Projected Savings: " + annual)
        TextWindow.WriteLine("Difference: " + difference)
        If (savings < annual) Then
          TextWindow.WriteLine("You DID NOT save what you projected.")
        Else
     TextWindow.WriteLine("")
        EndIf
      EndSub



    • Edited by Froshi Wednesday, October 19, 2016 10:32 PM
    Wednesday, October 19, 2016 10:18 PM

Answers

  • Hi !

    here is the right coding: and below my test with some numbers

    _________________________________________________________________________________________

    '  Roof gardens keep flat roofs cool in Summer – and also help insulate in winter. They require little maintenance and reduce energy bills significantly.
    Start()
    GetWithout()
    GetWith()
    GetTotalWithout()
    GetTotalWith()
    GetSavings()
    Savings()
    '------------------'
    Sub Start
    TextWindow.WriteLine("What is the name of your business?")
    name = TextWindow.Read()
    TextWindow.WriteLine("What do you project the annual savings to be?")
    annual = TextWindow.ReadNumber()
    TextWindow.WriteLine("--------------")
    EndSub
    Sub GetWithout
      TextWindow.WriteLine("Enter the energy bills WITHOUT the rooftop garden:")
      rooftop=0
        Months()
    EndSub
    Sub GetWith
      TextWindow.WriteLine("------------")
      TextWindow.WriteLine("Enter the energy bills WITH the rooftop garden:")
      rooftop=1
      Months() 
    EndSub
    Sub Months
      Month = "1=Janurary;2=Feburary;3=March;4=April;5=May;6=June;7=July;8=August;9=September;10=October;11=November;12=December"
      count=1
    While count <= 12 
      TextWindow.Write(month[count]+": ")
     
      If rooftop=0 then
        bills[count]=textwindow.Read()
        count=count+1
        EndIf

         If rooftop=1 then
           bills1[count]=textwindow.Read()
           count=count+1
      EndIf
     
     
     
    EndWhile
    TextWindow.WriteLine("")
    TextWindow.WriteLine("Here is what was entered")
    For count= 1 To 12
      If rooftop=0 then
        TextWindow.WriteLine(month[count]+": "+bills[count])
      Else
        TextWindow.WriteLine(month[count]+": "+bills1[count])
      EndIf
     
    EndFor
    EndSub

      Sub GetTotalWithout
      'SUM is for total WITHOUT
      total = 0
      For i = 1 To  Array.GetItemCount(bills)
        total = total + bills[i]  
      EndFor
      TextWindow.WriteLine("--------------")
      TextWindow.WriteLine("Your total WITHOUT is: " + total)
    EndSub

    Sub GetTotalWith
      'sums is for the total WITH
      total1 = 0
      For i = 1 To Array.GetItemCount(bills)
        total1 = total1 + bills1[i]
      EndFor
      TextWindow.WriteLine("Your total WITH is: " + total1)
      endsub
      
      Sub GetSavings
        savings = 0
        savings = total - total1
        TextWindow.WriteLine("Your total Savings are:"  + savings)
        EndSub
      
      Sub Savings
        difference = 0
        difference = annual-savings
        TextWindow.WriteLine("")
        TextWindow.WriteLine("Actual Savings: " + savings)
        TextWindow.WriteLine("Projected Savings: " + annual)
        TextWindow.WriteLine("Difference: " + difference)
        If (savings < annual) Then
          TextWindow.WriteLine("You DID NOT save what you projected.")
        Else
     TextWindow.WriteLine("")
        EndIf
      EndSub

    _________________________________________________________________________________________

    here the result in the textwindow screen:

    What is the name of your business?
    TOFU INC
    What do you project the annual savings to be?
    450
    --------------
    Enter the energy bills WITHOUT the rooftop garden:
    Janurary: 100
    Feburary: 100
    March: 100
    April: 100
    May: 100
    June: 100
    July: 100
    August: 100
    September: 100
    October: 100
    November: 100
    December: 100
    Here is what was entered
    Janurary: 100
    Feburary: 100
    March: 100
    April: 100
    May: 100
    June: 100
    July: 100
    August: 100
    September: 100
    October: 100
    November: 100
    December: 100
    ------------
    Enter the energy bills WITH the rooftop garden:
    Janurary: 50
    Feburary: 50
    March: 50
    April: 50
    May: 50
    June: 50
    July: 50
    August: 50
    September: 50
    October: 50
    November: 50
    December: 50
    Here is what was entered
    Janurary: 50
    Feburary: 50
    March: 50
    April: 50
    May: 50
    June: 50
    July: 50
    August: 50
    September: 50
    October: 50
    November: 50
    December: 50
    --------------
    Your total WITHOUT is: 1200
    Your total WITH is: 600
    Your total Savings are:600
    Actual Savings: 600
    Projected Savings: 450
    Difference: -150
    Press any key to continue...

    • Edited by YLedEditor Thursday, October 20, 2016 12:54 AM
    • Proposed as answer by Nonki Takahashi Wednesday, October 26, 2016 4:42 AM
    • Marked as answer by litdev Wednesday, November 2, 2016 8:17 PM
    Thursday, October 20, 2016 12:50 AM
    Answerer