none
Need help with small basic homework RRS feed

  • Question

  • This is what I have so far.  I can't figure out how to calculate the total calories from high fat foods and then the calories from low fat foods (the cut off is 20%). and also the list of high fat foods to eliminate from your diet. Someone please help.

    'MIS 105
    'Problem 17 - Menu Fat Analyzer

    'Here are the items from one of the dieter's menus
    menuItem[1] = "Brownberry 12 Grain Bread     "
    menuItem[2] = "Chocolate Chip Cookie         "
    menuItem[3] = "Peanut Butter Blizzard        "
    menuItem[4] = "Kung Pao Chicken              "
    menuItem[5] = "Teriyaki Chicken              "
    menuItem[6] = "Krispy Kreme Donut            "
    menuItem[7] = "Minibon Cinnamon Roll         "
    menuItem[8] = "Fruit & Maple Oatmeal         "
    menuItem[9] = "Salad w/ Blue Cheese Dressing "
    menuItem[10] = "Salad w/ Balsamic Dressing    "

    calories[1] = 110
    calories[2] = 160
    calories[3] = 530
    calories[4] = 260
    calories[5] = 460
    calories[6] = 190
    calories[7] = 381
    calories[8] = 290
    calories[9] = 205
    calories[10] = 100

    fatCalories[1] = 13
    fatCalories[2] = 72
    fatCalories[3] = 189
    fatCalories[4] = 81
    fatCalories[5] = 81
    fatCalories[6] = 40
    fatCalories[7] = 130
    fatCalories[8] = 40
    fatCalories[9] = 108
    fatCalories[10] = 18

    TextWindow.WriteLine("Food                          Cals  Fat Cal    Fat %")
    TextWindow.WriteLine("============================= ====  =======    =====")
    For i = 1 to Array.GetItemCount(menuItem)
    fatpercent= fatCalories[i]/calories[i]
      fatpercent=fatpercent*100
      fatpercent=Math.Round(fatpercent)
      TextWindow.WriteLine(menuItem[i] + Text.GetCharacter(9)+ calories[i]+Text.GetCharacter(9)+ fatCalories[i]+Text.GetCharacter(9)+ fatpercent+ "%")
    endfor


    TextWindow.WriteLine("")
    TextWindow.WriteLine("====================================================")
    TextWindow.WriteLine("Summary")
    TextWindow.WriteLine("")


    'Calculate and Display Total Calories
    arrayToSum=calories
    SumArray()
    totalcalories=arraytotal
    TextWindow.WriteLine("Total Calores =" +Text.GetCharacter(9)+text.GetCharacter(9)+totalcalories)


    'Calculate and Display Total Fat Calories
    arrayToSum=fatCalories
    SumArray()
    totalfatcalories=arraytotal
    TextWindow.WriteLine("Total Fat Calories =" +Text.GetCharacter(9)+ totalfatcalories)

    'Calculate and Display % of calories from fat

    SumArray()
     totalfatpercent=totalfatcalories/totalcalories
      totalfatpercent=totalfatpercent*100
      totalfatpercent=Math.Round(totalfatpercent)
      TextWindow.WriteLine("Total Fat Percent =" +Text.GetCharacter(9)+ totalfatpercent+ "%")
      TextWindow.WriteLine("")

    'Calculate total calories from high fat foods and low fat foods (separate totals)


    'High fat foods to eliminate from your diet
    TextWindow.WriteLine("High fat foods (over 20% fat) Cals  Fat Cal    Fat %")
    TextWindow.WriteLine("============================= ====  =======    =====")


    '********************************************************
    ' Subroutine: SumArray( )
    'Description: Subroutine that will add up the numbers in an array
    'Before calling the subroutine: Be sure to store the array to total in a variable called "arrayToSum"
    'After the subroutine is done: The total of the numbers in the array will be in a variable called "arrayTotal"
    '********************************************************
    arrayToSum[1] = 0
    Sub SumArray
      arrayTotal = 0
      For i = 1 To array.GetItemCount(arrayToSum)
        arrayTotal = arrayTotal + arrayToSum[i]
      EndFor
    EndSub

    Monday, October 14, 2013 9:56 PM

Answers

  • I guess the logic (pseudo-code) would be:

    Set high and low fat calories totals to 0

    Loop through each food

      Calculate the fat calories as a %

      If fat calories > 20% then add calories to high fat calories total

      Else add calories to low fat calories total

    EndLoop

    Display low and high fat totals

    Monday, October 14, 2013 10:39 PM
    Moderator
  • You should then use:

    totalcaloriesfromhigh=calories[i]+totalcaloriesfromhigh


    Jan [ WhTurner ] The Netherlands


    Wednesday, October 16, 2013 12:00 PM
    Answerer

All replies

  • I guess the logic (pseudo-code) would be:

    Set high and low fat calories totals to 0

    Loop through each food

      Calculate the fat calories as a %

      If fat calories > 20% then add calories to high fat calories total

      Else add calories to low fat calories total

    EndLoop

    Display low and high fat totals

    Monday, October 14, 2013 10:39 PM
    Moderator
  • How do I do that using the code I have? I'm supposed to use Sub SumArray for everything.  What values do I use?  How do I get the info using parallel arrays? I'm not sure how to write the code.

    Thanks

    Wednesday, October 16, 2013 12:30 AM
  • I'm assuming it should be something like:

    totalcaloriesfromhighfatfood=0
    If fatCalories[i]/calories[i] > 20 then
    totalcaloriesfromhigh= calories[i]


    endif

    TextWindow.WriteLine("total percent from high fat food " +totalcaloriesfromhighfatfood)

    Wednesday, October 16, 2013 1:22 AM
  • for example this works:

    totalcaloriesfromhigh=0

    If fatCalories[2]/calories[2] > .20 then
    totalcaloriesfromhigh=calories[2]

    endif

    TextWindow.WriteLine("total percent from high fat food " +totalcaloriesfromhigh)

    but now how do I do that using the array.  I don't know if I'm saying it right but basically replacing the [2]'s with [i] to run through them all and coming up with the total

    Wednesday, October 16, 2013 1:44 AM
  • You should then use:

    totalcaloriesfromhigh=calories[i]+totalcaloriesfromhigh


    Jan [ WhTurner ] The Netherlands


    Wednesday, October 16, 2013 12:00 PM
    Answerer
  • The fact that you have Small Basic homework is pretty awesome!!!

    Is this from a public school, private school, homeschool, or workshop?

    Thanks!


    Ed Price, SQL Server Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Friday, October 18, 2013 9:37 PM
    Owner