Tuesday, November 16, 2010

Tuesday- Handed in my Best Work for Repetition

  My best work that I have made so far, when it comes to the repetition assignments was handed in today, I hope I did well. I added color to this assignment, which I believe is extremely important as I stated in my previous post. However, the section that I believe will give me a higher mark is the processing section, because, to make my job easier I used a for statement to make my program much shorter. I am slowly starting to use much more sophisticated procedures, functions and keywords to make my program more efficient and compact to make it both easier for me (being the programmer) and the user. I am also posting the codes for questions 7, 9 and 10 on this post to help my peers work ahead on the repetition assignments and the main reason why I did not put 8 is because, I do not know if I did it properly, therefore I do not want to mislead anybody. 















#7 
for number : 1 .. 34


    colourback (green)


    colour (yellow)


    delay (500)


    put repeat ("*", number)


end for


%extro


colourback (blue)


colour (red)


put "Done!"

#9



var number1 : real
var answer : string
var negative_value : real


loop
    put "What is your number? " ..
    get number1
    if number1 not= 0 then 
    negative_value := number1 - number1 - number1
    put number1, " negative = ", negative_value
    put "Continue? (yes/no) " ..
    get answer
    else
    put "Enter valid number!"
    end if 
    exit when answer = "no"
end loop

# 10

% documentation section
% Gather a set of non-zero integers, and
% display both the number of positive
% and the number of negative integers processed.

%declaration section
var number : real
var answer : string
var negative_number_count : int := 0
var positive_number_count : int := 0

% processing section and input section

loop
    colourback ( black )
    cls
    colour ( yellow )
    put "Number? : " ..
    get number
    if number > 0 then
        positive_number_count := positive_number_count + 1
    elsif number < 0 then
        negative_number_count := negative_number_count + 1
    else
        colour ( white )
        put "Enter number that is not 0!"
    end if
        colour ( purple )
    put skip, "Positive number count = ", positive_number_count
        colour ( red )
    put skip, "Negative number count = ", negative_number_count
        colour ( 43 )
    put skip, "Continue? (y/n) " .. 
    get answer
    exit when answer = "n" or answer = "N"
end loop

% extro
put skip, "Done!"


  I hope this will help my peers proceed with repetition, I will post the rest on my next post, because I did not want to make this post extremely long. 

No comments:

Post a Comment