Fixing a broken program |
Author: Jordan Kidney ( kidney@cpsc.ucalgary.ca )
Date: Jan 31, 2006, minor modifications on Feb 3, 2006 by James Tam |
Background: The following small program was created, but there seems to be some syntactical and logical errors in the program. Your goal is to find and fix these errors so that the program compiles and runs correctly.
|
What the program should do:
The program reads in the users age and then prints what the user entered back out to the screen.
After this the program then checks the age to see what message it should print out in addition. The following conditions are used to check for what message should be printed out.
- If the users age is between 0 and 10 then print out the message "You are very young."
- If the users age is between 11 and 20 then print out the message "You are getting older."
- If the users age is greater then 20 then print out the message "You are still getting older."
So for example if we use the following inputs we should get the following output:
Input | Expected output |
2 | "You are very young." |
10 | "You are very young." |
11 | "You are getting older." |
20 | "You are getting older." |
21 | "You are still getting older." |
50 | "You are still getting older." |
|
Below you will find the original broken code with syntax and log errors.
Here is a link to the original broken code: BrokenExample1.p
Code |
Output from the compiler |
Line |
1: |(* ==============================================================================
2: |* File: WorkingExample1.p
3: |* Purpose: Working example for BrokenExample1.p. This program has no other use
4: |* but to the correction of basic syntax errors in a Pascal program.
5: |* Author: Jordan Kidney ( kidney@cpsc.ucalgary.ca )
6: |* Created on: Jan 31, 2006
7: |============================================================================== *)
8: |program (input,output);
9: |
10: |(* ========================== MAIN ============================================== *)
11: |begin
12: | var age : integer
13: |
14: | (* Read in the age of the user *)
15: | write('Please enter your age : ');
16: | readln(age);
17: | writeln('Your entered: ',age);
18: |
19: |
20: |
21: | (* Now print out some extra information *)
22: | write('Result: );
23: |
24: | if (age < 10) then
25: | writeln('You are very young.')
26: | else if (age < 20) then
27: | writeln('You are getting older.')
28: | else if (age > 20) then
29: | writeln('You are still getting older');
30: |
31: |end.
32: |(* ============================================================================== *)
|
> gpc BrokenExample1.p
BrokenExample1.p:29: unterminated string or character constant
BrokenExample1.p:22: possible real start of unterminated constant
>
|
|