Wednesday, November 10, 2010

It's time for...THE DAILY DOUBLE! (post)

Wow. So I actually survived taekwondo. Although it was so painful to even jog. -.-"
I've finished all my homework, and I was just studying my geography when I suddenly had a brain blast (Jimmy Neutron shout out!). You know number seven on the test? Well, I realize now that I did it completely incorrectly and in a very stupid manner.

Instead of using separate if statements, I used elsif keywords, which means that if there were more then one negative integer, my program wouldn't work. Like the perfectionist/OCD-ic I am, I just had to figure out the best way to write a program that would fit the requirements. It had to a) get 3 integers and b) display the sum of the positive integers only. Well, here you go:


% Declaration section
var integer1, integer2, integer3 : int
var totalsum : int


% Input section
put "Enter three integers separated by spaces: " ..
get integer1, integer2, integer3


% Processing section
if integer1 < 0 then
    integer1 := 0
end if


if integer2 < 0 then
    integer2 := 0
end if


if integer3 < 0 then
    integer3 := 0
end if


totalsum := integer1 + integer2 + integer3


% Output section
put "Sum of the positive integers: ", totalsum

Well, I truly understand the concept now, but it's a little bit too late. My computer studies mark just got thrown out the window. *sniffle* So much for the dream of an insanely high average.

-Grace

2 comments: