var hand, topHand1, topHandTotal : string
var income, topIncome, totalRightIncome, totalLeftIncome, totalIncome, prevIncome, num, leftNum, rightNum : int
var rightAvg, leftAvg, avgIncome : real
totalRightIncome := 0
totalLeftIncome := 0
totalIncome := 0
num := 0
leftNum := 0
rightNum := 0
put " " : 25, "Welcome to the Income Survey"
put ""
loop
num := num + 1
put "Are you left handed or right handed? " ..
get hand
if hand = "right" or hand = "Right" then
put "You are right handed."
elsif hand = "left" or hand = "Left" then
put "You are left handed."
end if
exit when hand = "done"
put "Please enter your income: $" ..
get income
totalIncome := totalIncome + income
if hand = "right" then
totalRightIncome := totalRightIncome + income
rightNum := rightNum + 1
elsif hand = "left" then
totalLeftIncome := totalLeftIncome + income
leftNum := leftNum + 1
end if
put ""
if num = 2 then
if income > prevIncome then
topHand1 := hand
topIncome := income
elsif num > 2 then
if income > prevIncome and income > topIncome then
topHand1 := hand
topIncome := income
end if
end if
end if
prevIncome := income
end loop
leftAvg := totalLeftIncome / leftNum
rightAvg := totalRightIncome / rightNum
avgIncome := totalIncome / num
if totalLeftIncome > totalRightIncome then
topHandTotal := "left"
elsif totalRightIncome > totalLeftIncome then
topHandTotal := "right"
end if
put ""
put "Summary for the given data"
put "Average income of left handed people: $", leftAvg
put "Average income of right handed people: $", rightAvg
put "A ", topHand1, " handed person makes the most, earning $", topIncome
put "On average, ", topHandTotal, " handed people earn more money"
put "Thank you for using the Income Survey Program"
|