Wednesday, February 15, 2006

Programming - an important test program

You have covered all of the skills needed to pass the programming test. The following program helps practice all of the skills:

  • Input
  • Loops (where you DON'T know the number of times to repeat at the start)
  • Conditions
  • Sums and Counters
  • Output

Here's the problem:

  • Write a program to ask for a number of prices to be input.
  • The prices should be added up so that a final total can be given at the end.
  • The input of prices should continue until a price of 0 (zero) is entered.
  • At the end, the following should be printed:

Total Price
Average Price
Highest Price
Lowest Price


How to start???

1. I always think it's easier to plan around the "main" idea of the program: input a price.

(These blanks will be filled in after the homework is submitted!)

2. Build the loop around the input. First of all decide whether it is a FOR...NEXT loop or a WHILE...WEND loop (remember to leave spaces so you can add other things inside the loop):



3. Add a counter so you can check the number of prices entered (so you can work out the average price)



4. Add the price to the running total



5. Check if the price is the highest so far



6. Check if the price is the lowest so far



7. Print the total, average, highest and lowest.

0 Comments:

Post a Comment

<< Home