previous page main index next page
 

Example 10

A youth club runs a disco every Friday, Saturday and Sunday. They sell different flavors of chips at 65c per bag. The youth club requires a program which adds up the total number of bags of chips of a particular flavor sold on the three nights and calculates the total money raised.

1. Design a Solution

Our first attempt is:

1.  get information from user
2.  calculate money raised
3.  print out results

Step 1 becomes:

1.1  ask user to enter flavor of chips
1.2  read in flavor
1.3  ask user for number sold on Friday
1.4  read in number sold on Friday
1.5  ask user for number sold on Saturday
1.6  read in number sold on Saturday
1.7  ask user for number sold on Sunday
1.8  read in number sold on Sunday

Step 2 becomes:

2.1  calculate total bags sold
2.2  calculate total money raised

Step 3 becomes:

3.1  print out flavor
3.2  print number of bags sold
3.3  print total money raised

The complete design is shown below:
 

1.1  ask user to enter flavor of chips
1.2  read in flavor
1.3  ask user for number sold on Friday
1.4  read in number sold on Friday
1.5  ask user for number sold on Saturday
1.6  read in number sold on Saturday
1.7  ask user for number sold on Sunday
1.8  read in number sold on Sunday

2.1  calculate total bags sold
2.2  calculate total money raised

3.1  print out flavor
3.2  print number of bags sold
3.3  print total money raised

 
2. Code the Program
  • look again at what the program needs to do and decide how many variables you need
  • what type of variables are they?
  • what will you call them?
  • if you're not too sure, then see your teacher before you go any further
  • use the design above and type in the code for the program
  • save the program as chips1.pas
  • compile and run the program
     

3. Test the Program

  • draw up a table and choose some suitable test data
  • write a short summary of the results
     

4. Evaluate the Solution

  • write a report on your solution and suggest any improvements that you could make

[From now on we're not always going to ask you to do steps 3 and 4 ie to test the program and evaluate it. That's not because it isn't important, but because we think you should really do it as a matter of course and without needing to be asked every time. If it's necessary to look at this aspect for any particular examples then we will say so. See your teacher if there's any doubt.]
 

previous page main index next page
 
©2001 by Mike Hardy