%Declaring an array called count
var count : array 0 .. 10 of int
%Declaring other variables
var errorl : string
var num : int
%Beginning a procedure called invalid which shows up when user enters anything
%else other than a number from 0-10
procedure invalid
put "The value you have entered is either a letter or an invalid value."
put "Please re- enter a mark between 0-10"
end invalid %Ending the prodcedure
%Beginning a for loop
for number : 0 .. 10
%Initializing count to 0
count (number) := 0
end for
color (3)
locate (1, 1)
put "++++++++++++++++++++++++++"
locate (2, 1)
put "The Mark Frequency Program"
locate (3, 1)
put "++++++++++++++++++++++++++"
locate (5, 1)
put "This program asks the user to input a series of marks between 0 - 10."
locate (6, 1)
put "The program automatically stops the input of data once -99 is entered."
locate (7, 1)
put "The program then displays how many students got the same mark."
locate (9, 1)
put "Please enter the the marks. Input -99 to end the input of data."
locate (10, 1)
put "Press <ENTER> after each mark."
put ""
loop
%Beginning error trap
loop
get errorl : *
%Condition applied if user inputs a number between "0"-"9"
if errorl >= "0" and errorl <= "9" then
exit
elsif
%Condition applied if user inputs "-99"
errorl = "-99" then
exit
%Condition applied if user inputs a letter or word
elsif errorl >= "A" and errorl <= "z" then
invalid
%Condition applied if user inputs a number below "0"
elsif errorl < "0"
then
invalid
else
%Condition applied if user inputs anything else
invalid
end if
end loop
%Converting the information entered by user into integer
num := strint (errorl)
%Exit condition
if num = - 99 then
exit
end if
%Condition applied if the number entered is greater than 10
if num > 10 then
invalid
end if
%Using counters to count the number of times a same number was entered
if num = 0 then
count (0) := count (0) + 1
elsif num = 1 then
count (1) := count (1) + 1
elsif num = 2 then
count (2) := count (2) + 1
elsif num = 3 then
count (3) := count (3) + 1
elsif num = 4 then
count (4) := count (4) + 1
elsif num = 5 then
count (5) := count (5) + 1
elsif num = 6 then
count (6) := count (6) + 1
elsif num = 7 then
count (7) := count (7) + 1
elsif num = 8 then
count (8) := count (8) + 1
elsif num = 9 then
count (9) := count (9) + 1
elsif num = 10 then
count (10) := count (10) + 1
end if
end loop
delay (200)
cls
put "+++++++++++"
put "The Results"
put "+++++++++++"
put ""
for number1 : 0 .. 10
%Displaying how many students got the same marks
put count (number1), " student(s) recieved ", number1, "/10."
end for
put ""
colour(4)
put "Press F1 to rerun the program" |