Need to fix this code for my pascal assignment [closed] - pascal

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I was assigned a program to write. here are the instructions
Problem Solving and Programming
Insurance companies are interested in software that will better assist their customers based on the study carried out by the NMTRO. A trial run of the software should be implemented where up to 30 customers may be attended to per day.
You are required to write a pseudocode or draw a flowchart that will accept customer’s information (First Name, Last Name, Gender, Model of car, Category of car, Insurance Company, TOC, whether or not an Antitheft device has been installed, Premium and value of car). Calculate the compensation payment for each customer based on calculation criteria given in Task B of the spreadsheet section.
At the end you are to:
a. Calculate the number of vehicles insured Fully Comprehensive
b. Find the highest vehicle cost
c. Calculate the percentage of owners who installed antitheft mechanism
d. Prompt the user for a customer’s name and search for and display the customer’s information including the compensation payment to be made.
Design and implement a trace table that accepts data for 6 members (same data as the spreadsheet). The table should track the Value of car, TOC, Premium, antitheft installed and insurance payment. The total premium of all customers should be calculated
here is the code `
VAR
First_Name, Last_Name, Model, Insurance_company, stop: array[1..30] of string;
Compensation, V_O_C, P_O_A, A_O_C: array [1..30] of real;
Gender: array [1..30] of char;
T_O_C, Premium, X, Count, CountA, Highest, Category: array [1..30]of integer;
Antitheft_installed: array [1..30] of boolean;
Begin
Count:=0;
CountA:=0;
Highest:=0;
FOR X = 1 to 30 DO
Repeat
Writeln ('Please enter First_Name');
Readln (First_Name[X]);
Writeln ('Please enter Last_Name');
Read Last_ Name [X]
Writeln ('Please enter Gender, M or F');
Readln Gender[X]
Until "stop"
IF Gender<>M and Gender <>F then
Print "You can only enter M or F for Gender"
ENDIF
Repeat
Writeln "Please enter Model"
Read Model[X]
Writeln "Please Enter number corresponding with Category of car"
Writeln "Please Enter 1 for LCR-70"
Writeln "Please Enter 2 for LCR-71"
Writeln "Please Enter 3 for LCR-72"
Writeln "Please Enter 4 for LCR-73"
Read Category[X]
Until "stop"
If category >=5 then
Writeln "Please select one of the options above"
ENDIF
Repeat
Writeln "Please enter 1 if Type Of Coverage is FC"
Writeln "Please enter 2 if Type Of Coverage is TPO"
Read TOC[X]
Until "stop"
IF TOC >=3 Then
Writeln "Only 1 or 2 can be entered here"
ENDIF
Repeat
Writeln "Please enter Antitheft installed Yes or No"
Read Antitheft installed[X]
IF Antitheft = "yes" then
CountA =CountA+1
P_O_A= CountA/Max * 100
ENDIf
Writeln "The percentage is" P_O_A[X]
Writeln "Press 1 for BBC"
Writeln "Press 2 for Nationwide"
Writeln "Press 3 for IWCI"
Writeln "Press 4 for Statefarm"
Read Insurance company[X]
IF Insurance_company =1 then
Writeln "Your premium is $2700"
ENDIF
IF Insurance_company =2 then
Writeln "Your premium is $3500"
ENDIF
IF Insurance_company =3 then
Writeln "Your premium is $1675"
ENDIF
IF Insurance_company =4 then
Writeln "Your premium is $1950"
ENDIF
IF insurance_company>= 5 then
Writeln "Please choose one of the options above"
ENDIF
Read Premium
Writeln "Please enter value of car"
Read V_O_C[X]
While TOC= " FC" Do
Count=Count+1
ENDWhile
Writeln "The total number of vehicles fully comprehensively insured is" Count[X]
IF V_O_C > Highest then
Highest= V_O_C
Writeln "The Highest value of car is", Highest[X]
IF V_O_C <1 and TOC= "FC" then
Compensation= V_O_C * 0.5 Else
IF A_O_C >=2 and A_O_C <=4 and TOC= "FC" then
Compensation= V_O_C * 0.4 Else
IF A_O_C >=5 and A_O_C <=7 and TOC= "FC" then
Compensation= V_O_C * 0.3 Else
IF A_O_C >=8 and A_O_C <=10 and TPO= "FC" then
Compensation= A_O_C * 0.2 Else
IF A_O_C >10 and TOC= "FC" then
Compensation= V_O_C * 0.1 Else
Compensation= V_O_C * 0
Writeln "The Frist name of the customer is" First_Name[X]
Writeln "The Last name of the customer is" Last_Name[X]
Writeln "The customer Gender is" Gender[X]
Writeln "The model of car the customer own is" Model[X]
Writeln "The category of car customer own is" Category[X]
Writeln "The insurance company the customer is with is" Insurance_ Company[X]
Writeln "The type of coverage for customer is" TOC[X]
Writeln "The customer antitheft yes or no" Antitheft_ installed[X]
Writeln "The premium for customer is" Premium[X]
Writeln "The value of car for customer is" V_O_C[X]
Writeln "The customer compensation is" Compensation[X]
Writeln "Enter 11 to add a customer"
end.`
i get these errors
17 / 26 clunis.pas Error: Type mismatch
17 / 27 clunis.pas
Error: Incompatible types: got "Array[1..30] Of LONGINT" expected "LONGINT"
19 / 13 clunis.pas
Fatal: Syntax error, UNTIL expected but identifier LAST_ found

This is not correct :
FOR X = 1 to 30 DO
The semantics of the for command means that X is being assigned with the value 1, so you should use instead
For X := 1 to 30 do
This is not correct :
ReadLn Category[X]
Read is a procedure, it should have its parameters delimited by parenthesis.
ReadLn(Category[X]);
Again this is not correct :
Until "stop"
Until expects a boolean expression (any expression that returns true or false). A string is not a boolean expression.
ENDIF
Pascal is not basic. The if command is not "ended" by the end. What is ended is the block of commands started by BEGIN, so there is no ENDIF, ENDCASE, ENDWHATEVER in Pascal, only BEGIN and END.
END;
This is not correct :
Read Antitheft installed[X]
Besides the error of not using parenthesis around procedures parameter lists (both WriteLn and ReadLn are procedures from the system unit), you are trying to use a variable with white space inside its name, thats not allowed.
This is not correct:
Count=Count+1
Pascal assignment operator is :=, not =. If you want to increment a variable, you can use Inc(Count) to increment it.
This is not correct:
IF V_O_C <1 and TOC= "FC" then
As for Pascal the and operator has precedence over relop operators (= and <) the compiler will operate first the and, resulting in the following equivalent expression.
IF (V_O_C < (1 and TOC)) = "FC" then
There are too many errors in your code.

Related

I need help writing a code for this question

Im using pycharm
Write a program that will calculate tax on the user's annual salary. It must :
1. ask the user to enter their name,
2. ask the user to enter their annual salary
3. print their tax bill on screen
However, Australian tax laws are complicated.
They follow these rules:
•0 – $18,200 Nil ($0 tax paid)
•$18,201 – $45,000 19 cents for each $1 over $18,200
•$45,001 – $120,000 $5,092 plus 32.5 cents for each $1 over $45,000
•$120,001 – $180,000 $29,467 plus 37 cents for each $1 over $120,000
•$180,001 and over, $51,667 plus 45 cents for each $1 over $180,000
This function works and does not require any dependencies to work.
def taxesDue(x:float):
'''Function that takes in a person's yearly salary (unit: AUD) and returns the taxes due (unit: AUD)'''
if(x <= 18200):
return 0 # lucky person
elif(x <= 45000):
return round(0.19*(x-18200), 2)
elif(x<= 120000):
return round(5092+0.325*(x-45000), 2)
elif(x <= 180000):
return round(29467+0.37*(x-120000),2)
else:
return round(51667+0.45*(x-180000)*0.45, 2)
The sample output is
taxesDue(16500)
>0
taxesDue(18201)
>0.19
taxesDue(1e6) # scientific notation for 1 million (float)
>217717.0
Since all of us were new to coding at one point. Some explanation on things you will likely encounter on your journey deeper into Python.
The function's input is the salary in AUD (can be an integer like 20000 or a float such as 20000.95 where the decimals represent cents. Therefore, I rounded the taxes due to two digits through round(y, 2). In case the input salary is always of type int you can leave the rounding out as the output will naturally only have two decimals.
Speaking of float and int. Types in Python are dynamic so the float:x in the function's argument list is syntactic sugar (nice to look at for the developer/user but no impact on the rest of the code) to emphasize that a floating point number (the salary) goes in rather than a string str like x=Hello IRS. Note that int is a subset of float so float is more general.
The if/elif/else iterates through the conditions (e.g. x <= 45000). elif and the final else is only checked if none of the previous conditions was met. Note that this naturally reflects your task at hand.
Any function is exited as soon as any of the return's is reached.
Comments such as #lucky or the the comment right underneath the function's head '''Function... will go into the docstring. In turn, the developer can retrieve it when running
?taxesDue
If you need to print the result run
x = 475000 # or whatever salary you can think of
print(taxesDue(x))

Why does syntax error appear after running code?

presently learning how to code in pascal and vba. Assisting my daughter who is preparing for examinations next year. I am stuck on a problem concerning her present assignment. After running the code the following errors were received:
main.pas(1,2) Fatal: Syntax error, "BEGIN" expected but "identifier N" found
Fatal: Compilation aborted
Tried fixing the code, but as i said I have just started learning to code.
n: integer; (*n is ID number for each candidate*)
DV: integer; (*DV is the number of district votes available*)
VR: integer; (*VR is the number of votes received by the candidate in
the district*)
x: integer;
y: integer;
Divide: integer;
found: Boolean;
n: array[1..10] of integer; (*n is an array of 10 integers*)
Names: array[1…10] of string = (‘Richards’, ‘Gumbs’, ‘Carty’,
‘Fleming’, ‘Jones’, ‘Amorowat’, ‘De la cruz’, ‘Walker’,
‘Brooks’, ‘Baker’);
DV: array[1…10] of integer = (‘200’, ‘900’, ‘700’, ‘100’, ‘80’, ‘15’,
‘6, ‘20’, ‘50’, ‘1’);
VR: array[1…10] of integer = (‘50’, ‘700’, ‘600’, ‘20’, ‘30’, ‘2’,
‘6, ‘3’, ‘30’, ‘2’);
For x := 1 to 10 do
Begin
Repeat
Found:=false;
writeln('Enter Candidate ID Number: ’);
readln(n);
For y:= 1 to 10 do
if n = n[y] then
Found = true;
writeln(‘Name of Candidate is’ Names: array[1] ‘.’);
readln;
writeln(‘Number of votes available in the District is’
DV: array[1] ‘.’);
readln;
writeln(‘Number of votes received by the Candidate in the
District is’ VR: array[1] ‘.’);
readln;
Endif;
For y:= 1 to 10 do
if n = n[y] then
Divide:= (DV: array[1] DIV VR: array[1]);
Result:= Divide;
writeln(‘The percentage of votes received by’ Names:
array[1] ‘is’ Result ‘.’);
readln;
if Result:>= 0.20 then
writeln(‘The candidate,’ Names: array[1] ‘is to receive a
refund.’);
readln;
Elseif
writeln(‘The candidate,’ Names: array[1] ‘will not receive
a refund.’);
readln;
Endif;
Endif;
End;
The expected result is to choose a candidate by his ID number which would lead to his name, the number of vote available in a district and the number of votes the candidate obtained being displayed. it would then result in a calculation between the two vote counts (division) and if the percentage is greater than 20% he would receive a refund, if less than 20% he would not receive a refund. either result should be displayed.
I'm afraid that you q, as it currently stands, isn't really suited to SO
because SO is really about specific (single) programming problems, not
incrementally debugging source code (see Sertac's comment), nor providing
online tutorials, which I think you probably need at this point. And I feel
rather uncomfortable about posting this as an answer, because it isn't one
in the normal SO sense. However it seems to me that you could use a few pointers:
Unless you absolutely have to use the online compiler, download
and use a free online one like Free Pascal, which is well supported, uses
standard Pascal syntax, and I'm sure there are basic first-time tutorials
available. See here to download Lazarus, which is an excellent IDE for Free Pascal (which is included
in the install) and here for an introductory tutorial.
Secondly, there are structural and syntactic elements of your source-code
which are definitely not standard Pascal, in particular endif and elseif.
Another example is that in standard Pascal, you have to surround a string (like your
Richards, etc) with single-quotes ', not precede the string by a back-quote. This is very possibly the cause of your "illegal character" error
For a decent Free Pascal introductory
tutorial see here and this youtube tutorial, both found by googling
"free pascal" introductory tutorial.
Fourthly, your online compiler ought to be complaining about the endif abd elseifs, the incorrectly string formatting and the fact that several of your variables are duplicated (DV and VR used as the names of an integer variable and an array, for example as in Pascal, identifiers within the same 'scope' need to have unique names (the fact that I should explain what 'scope' means is a sign that what the q needs is a tutorial).

why am i getting 22 / 3 itprog~1.pas Fatal: Syntax error, ; expected but ELSE found

PROGRAM approvedapplicants(input,output);
uses crt;
var
applcntname,housingcomm,clarendon_court,providence_gardens,
sangre_grande_villas:string;
slry,spcslry:integer;
c_qual_sal,s_qual_sal,p_qual_sal,qualifying_salary:integer;
BEGIN
writeln('enter applicant name, salary, spouce salary');
readln(applcntname,slry,spcslry);
writeln('enter housing community');
readln(housingcomm);
BEGIN
qualifying_salary:=0;
IF(housingcomm=clarendon_court)
then
qualifying_salary:=$12500;
writeln('you have selected clarendon court!');
readln(c_qual_sal) ;
end if ;
else if(housingcomm=sangre_grande_villas)then
qualifying_salary:=$9500;
writeln('you have selected sangre grande villas!');
readln(s_qual_sal);
end if ;
else(housingcomm=providence_gardens)then;
qualifying_salary:=$7500;
writeln('you have selected providence gardens!');
readln(p_qual_sal);
end if;
END.
Ordinarily, on SO, we don't post answers to homework/coursework, but your code is so far wide of the mark that I think it's ok to make an exception in this case.
Try compiling and running this program, which I think does pretty much what I think you are intending, then I'll explain a few things about it:
program approvedapplicants(input,output);
uses crt;
var
ApplicantName,
HousingCommunity,
ClarendonCourt,
ProvidenceGardens,
SangreGrandVillas :string;
Salary,
SpouseSalary,
QualifyingSalary : Integer;
CQualSal,
PQualSal,
SQualSal : Integer;
slry,spcslry:integer;
begin
ClarendonCourt := 'Clarendon Court';
ProvidenceGardens := 'Providence Gardens';
SangreGrandVillas := 'Sangre Grand Villas';
QualifyingSalary := 0;
writeln('enter applicant name');
readln(ApplicantName);
writeln('enter salary');
readln(Salary);
writeln('enter spouse salary');
readln(SpouseSalary);
writeln('enter housing community');
readln(HousingCommunity);
if (HousingCommunity = ClarendonCourt) then begin
QualifyingSalary := $12500;
writeln('you have selected clarendon court!');
readln(CQualSal);
end
else
if(HousingCommunity = SangreGrandVillas)then begin
QualifyingSalary := $9500;
writeln('you have selected sangre grande villas!');
readln(SQualSal);
end
else
if HousingCommunity = ProvidenceGardens then begin
QualifyingSalary :=$7500;
writeln('you have selected providence gardens!');
readln(CQualSal);
end;
end.
Firstly, notice how much easier it is to read and follow its logic. This is mainly
because of
The use of a layout (including indented blocks) which reflects the logical
structure of the code.
The use of consistent, lower case for keywords like program, begin, end, etc.
Keywords are usually the least interesting contents of source code, and it is distracting
to have them SHOUTing at you.
The avoidance of arbitrarily dropping characters from variable names (like the "i"
and second "a" of "applicant". In the days of interpreted code running on slow machines there was
argubably some justification for this, but not any more imo. Likewise, the avoidance
of underscores in variable names - admittedly this is more of a personal preference, but
why have you used them everywhere except the applicant's name?
Secondly, you still have quite a bit of work to do.
Having 3 different variables for the salary (?) numbers you prompt the user
for, one for each of the 3 communities, is probably a bad idea unless you will
subsequently want to work with all 3 figures at the same time. Also, you haven't provided text prompts to tell the user what information to enter for the readln(c_qual_sal) etc statements. It wasn't obvious to me what you intend, so I have not tried to guess.
The way you echo the user's choice of community is just creating you a maintenance
headache (what if you want to add more communities later?). It would be better
to have a variable which you set to whichever of the community names matches
what the user has entered.
You have 3 statements to execute for each community, which are duplicated for
each community. The only one you actually need is the QualifyingSalary one -
the others can execute regardless of the inputted community.

Vbscript loop, if then issue

I need some assistance. I am new to vbscript and I have a problem/question.
I am trying to give an end user the ability to start a program over.
I have done research on MSDN and googled various other sites that involve tutorials based on if then statements, subroutines, functions and do,while,until loops
all the loop tutorials or explanations have a program looping through numbers and string lengths. I have developed a common stock transaction program:
'Stock Transaction Program
Option Explicit
Dim stockPrice, commission, stocksBought, stockCommission, stockTotal, totalCost, tryAgain
Wscript.StdOut.Write "Stock price: "
stockPrice = CDbl(Wscript.StdIn.ReadLine)
Wscript.StdOut.Write "Number of stocks bought: "
stocksBought = CDbl(Wscript.StdIn.ReadLine)
Wscript.StdOut.Write "Stock Commission percentage in whole number (i.e 2 for 2%): "
commission = CDbl(Wscript.StdIn.ReadLine)
stockTotal = stockPrice * stocksBought
stockCommission = commission * stockTotal / 100
totalCost = stockCommission + stockTotal
Wscript.StdOut.WriteLine "You payed a total commission of $" & stockCommission & " on the stocks you bought."
Wscript.StdOut.WriteLine "Your total price for you purchasing " & stocksBought & " stocks is $" & totalCost & "."
After this program concludes, I would to give the end user an option to evaluate another stock price..etc.
Wscript.Stdout.Writeline "Would you evaluate another stock price? (i.e y or n): "
tryAgain = lcase(wscript.stdin.readline)
My logic assumes that you would now proceed with an if statement of some kind that basically says: that if tryAgain equals "y" then proceed back to the top, if "n" then exit program with a thank you conclusion, if invalid character then state that the end user entered an invalid response, allowing them the oppurtunity to try again.
I couldn't figure it out. functions and subroutines need arguments (i assume) and subroutines do not give data output. functions do but this code doesnt classify. I was hoping that their was a syntax that would allow the program to start over. I think a loop of some kind is probably the answer but i dont have the knowledge or the experience.
Is their anyone that can assist me???
Thanks
This could be one of the simplest solutions.
Option Explicit
Dim stockPrice, .... , tryAgain
Do
'....
' your stocks code
'....
Wscript.Stdout.Writeline "Would you evaluate another stock price? (i.e y or n): "
tryAgain = lcase(wscript.stdin.readline)
Loop While tryAgain="y"

Pascal programming help

I posted this earlier and it got closed because I did not show my try at coding it, so here is the question:
SECTIONS
$160 = section 1
$220 = section 2
$280 = section 3
$350 = section 4
$425 = section 5
Develop pseudocode that accepts as input the name of an unspecified number of masqueraders who each have paid the full cost of their costume and the amount each has paid.
A masquerader may have paid for a costume in any of the five sections in the band. The algorithm should determine the section in which the masquerader plays, based on the amount he/she has paid for the costume. The algorithm should also determine the number of masqueraders who have paid for costumes in each section.
The names of persons and the section for which they have paid should be printed. A listing of the sections and the total number of persons registered to play in each section should also be printed, along with the total amount paid in each section.
Here is my try at it: *Note this is programmed in Pascal, and I need help fixing it up and finishing it. Please help and thanks again.
program Masqueraders;
uses
WinCrt; { Allows Writeln, Readln, cursor movement, etc. }
const
MAX = 5; {this determine the amount of masquarader entered}
Type
listname = Array[1..MAX] of string;
listsect = Array[1..MAX] of string;
var
names : listname;
sections : listsect;
i, amount, TotalMas, TotalAmt, c1, c2, c3, c4, c5, amt1, amt2, amt3, amt4, amt5 : integer;
begin
amount := 1;
while amount <> 0 do
begin
i := i + 1;
readln(names[i]);
readln(amount);
if(amount = 160) then
begin
c1 := c1 + 1; {Count the number of persons for section 1}
amt1 := amt1 + amount; {accumulate the amount for section 1}
sections[i] := 'Section 1';
end;
if(amount = 220) then
begin
c2 := c2 + 1; {Count the number of persons for section 1}
amt2 := amt2 + amount; {accumulate the amount for section 1}
sections[i] := 'Section 2';
end; {end the IF for section 2}
if(amount = 280) then
begin
c3 := c3 + 1; {Count the number of persons for section 1}
amt3 := amt3 + amount; {accumulate the amount for section 1}
sections[i] := 'Section 3';
end; {end the IF for section 3}
if(amount = 350) then
begin
c4 := c4 + 1;
amt4 := amt4 + amount;
sections[i] := 'Section4';
end; {end If for section 4}
if (amount = 425) then
begin
c5 := c5 + 1;
amt5 := amt5 + amount;
sections[i] := 'Section5';
end;{end the while loop}
TotalMas := c1 + c2 + c3;
TotalAmt := amt1 + amt2 + amt3;
writeln('Name Section'); {Heading for the output}
for i := 1 to MAX do
begin
write(names[i]);
writeln(' ',sections[i]);
end;
writeln('Section 1: ');
write('Masquader: ', c1);
write('Amount: ', amt1);
writeln('Total Number of Masquarader: ', TotalMas);
writeln('Total Amount Paid by masquarader: ', TotalAmt);
end;
end.
In short, it should accept an undefined number of people and assign them to their respective sections based on the amount of money they entered, then calculate the number of people in each section. This is my current output:
Name John Money=160 Section 1
Name Keith Money=220 Section John
This is what I want:
Name John Money=160 Section1
Name Keith Money=220 Section2
I'm not really familiar with Pascal so I can't tell you how to fix this but one issue I notice is that your code seems to violate the "DRY" rule: Don't Repeat Yourself. The code inside each if amt = xxx block looks almost exactly the same, so is there a way you can write that code once, and then call your code with different parameters each time? Something so that you're not rewriting the same code five times.
Here's are a few hints to improve your code:
Do you think there might be a way to print "Section {i}" in your final loop without looking it up using sections[i], thereby negating the need for the array completely?
How could you build this so that adding a section 6 wouldn't require modifications to your code?
listname and listsect are awfully similar, what modifications to your code could you do to eliminate the need to have two identical definitions?
What happens if the user enters 0 for the amount the third time they are prompted?
Note: one of these hints should point you directly to the source of your problem.
Here are the problems I see:
The requirements say an "unspecified number of masqueraders" but you have set the max to 5. You can't store the list of names in a fixed size array if there are possibly going to be more than 5 masqueraders. As is, the app may either crash or corrupt memory (depending on the version of Pascal you're using) when user enters the 6th masquerader. If you are allowed to print the masquerader's Name and Section immediately after it is input, then you should print that right after the user inputs the Name and Amount (not after the input while loop). However, if it is required that you print the list of Names and Sections after all input, then you need to store the Name+Section in a variable length data structure like a linked list or even simpler a string.
The variables c1 to c5 and amt1 to amt5 would be better declared as two arrays (c and amt) of 1..MAX instead of 10 variables. When user inputs the amount, use it determine the section number which then can be used as the index into the c and amt arrays.
Not sure what implementation of Pascal you're using but it would be safer to initialize all variables before use otherwise they could contain unpredictable values.
The sections array is unnecessary. All it ends up containing is the title of the section which doesn't need to be calculated or stored.
If you used a repeat/until loop instead of a while loop, it would avoid the slightly kludgy "amount := 1" initialization at the top to enter the while loop. The repeat/until would be until Amount = 0.
TotalMas is only adding c1 to c3 (what about c4 and c5)?
TotalAmt is only adding amt1 to amt3 (what about amt4 and amt5)?
The for-loop to print the names and section is completely wrong, see points 1 and 4.
Hope this helps and let me know if you need clarification on any points.
My gripes with this code:
1) The variable names stink. Virtually all of them are way too short, they do not communicate what they do.
2) The wrong loop control structure is used here.
3) I see virtually identical code repeated 5 times. This is simply crying out for arrays.
4) The comments explain what you are doing, not why you are doing it. Half of them are virtually completely useless, if you're going to comment an end you should simply comment it with the identity of whatever it's an end to. end; //if I see only one comment that even tries to explain why and you've got it wrong as you're mixing up people with sections.
5) Your sections array accomplishes nothing useful. The assignments to the values are always fixed and thus there is no reason to store them at all--if you need the labels you can create them at print time.
6) You are assuming there are only going to be 5 people. That's not given in the problem--there's 5 sections.

Resources