IPT - A Virtual Approach IPT A Virtual Approach by Peter Whitehouse
Quick Links:
Information and Intelligent Systems Social and Ethical Implications Human Computer Interaction Software and Systems Engineering eXercise Files Course Outline and Assessment A-Z of Geeky Acronyms Terrace Work Program 2004 Sillybus FAQ = Frequently Asked Questions Help

eXercise #8

Iteration using WHILE...DO

  1. Write a simple program which accepts a line of input from the user and which reports the number of characters typed.

  2. Write a simple program which accepts a line of characters in a similar fashion to the previous question, from the keyboard and which returns to the screen the number of spaces, vowels and consonants in the typed line. A case statement may prove helpful.

  3. Write a small program for the following task. The user inputs a number between 0 and 50 and the machine prints that many asterisks on the next line. Note that you should use a while loop to solve this problem.

  4. Write a small code fragment which asks the user for an integer and which then reports the whole number power of 2 which this number is equal to or exceeds. For example, if the user types in the number 1000, the machine should respond with the value 9 because 2 to the power of 9 = 512 which is less than 1000 but 2 to the power of 1O = 1024 and this is greater than 1000.

  5. Convert the following code fragment to one which uses a while statement. Note that i is an integer variable. Note also that this fragment outputs the squares from 1 to 20 inclusive. Make certain your code also does this.
        i := 0;
           i := i+l;
        until i*i>=20


©Copyright t 1992..2018+. Edition 26.150117
Creative Commons License
This work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 2.1 Australia License