Chapter 6: Repetition Additional Exercises, Part 1
Infinite Loops Ch06_extra01 % The "Ch06_extra01" program % Displays the square of a number input by the user var number : real loop put "Enter a number (decimals are acceptable): " ..
get number put "The square of ", number, " is ", number ** 2 end loop Revise the program to create programs as follows:
Ch06_extra02 Displays the square root of the number.
Ch06_extra03 Displays the number as a percentage out of 75.
Ch06_extra04 Displays the result when 2 is raised to the power of the number.
Chapter 6: Repetition Additional Exercises, Part 1 Page 2 of 3
Conditional Loops Ch06_extra05 Revise the program above to stop and display the message “Program has finished” when the user enters a negative number.
Ch06_extra06 Create a program that tells users they are about to play a guessing game, where they will try to guess a mystery letter of the alphabet (lower case letters only). Tell them “Sorry, wrong guess” for an incorrect guess and “Congratulations, you are correct!” for a correct guess.
Ch06_extra07 Revise the previous guessing game so that there are three correct letters.
Counted Loops Ch06_extra08 Revise the program on page 103 of the text book to calculate the average of a person’s six paycheques. Show dollar signs and two decimal places.
Ch06_extra09 Enter and run the following program:
% The "Ch06_extra08" program var letter : string put "You get 10 tries to guess the mystery letter of for count : 1 .. 10 put "Enter your guess: " .. get letter exit when letter = "z" put "Sorry, wrong guess." end for
the alphabet (lower case only)"
Ch06_extra10 Revise the previous program so a wrong guess receives response in the pattern, “Sorry wrong guess. That was guess 1.”
Chapter 6: Repetition Additional Exercises, Part 1 Page 3 of 3
Counting in Multiples Ch06_extra11 This program tests the user’s understanding of Turing’s counting in multiples feature.
% The "Ch06_extra11" program % Tests the user's understanding % of Turing's counting in multiples feature var guess : int put “This program is going to test your understanding of Turing’s counting in multiples feature.” put "It will count in 2s from 10 to 27." put "Enter your prediction of the last result (negative numbers are acceptable): " .. get guess for count : 10 .. 27 by 2 put count end for put "Your guess was ", guess Ch06_extra12 Revise the previous program so that the user inputs not only the guess but also the multiple, the start number and the stop number.
Chapter 6: Repetition Additional Exercises, Part 1 Page 4 of 3
The rand and randint procedures Ch06_extra13