3.2 Solutions

  1. if temperature > MAX_TEMP then
       put "Porridge too hot"
    elsif temperature < MIN_TEMP then
       put "Porridge too cold"
    else
       put "Porridge just right - eat it all up."
    end if 
    1. Reject
    2. it will not print anything since there is no else to go with the first if
  2. if a < b and a < c then
       put a
    elsif b < c then
       put b
    else
       put c
    end if 
  3. if item < 0 then
       negSum := negSum + item
    elsif itme > 0 then
       posSum := posSum + item
    else
       zeroCount := zeroCount + 1
    end if 
  4. var year : int
    var leapYear : boolean
    
    %this part is not necessary for the fragment
    put "Enter a year"
    get year
    %end this part
    
    if year mod 100 = 0 and year mod 400 not= 0 then
        leapYear := false
    elsif year mod 100 = 0 then
        leapYear := true
    elsif year mod 4 = 0 then
        leapYear := true
    else
        leapYear := false
    end if
    
    %this part is not necessary for the fragment
    if leapYear then
        put "The year ", year, " is a leap year."
    else
        put "The year ", year, " is NOT a leap year."
    end if
    %end this part