-6

I was assigned a program to write. here are the instructions

Problem Solving and Programming

  1. 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.

  1. 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

1 Answers1

5

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.

Jorge Aldo
  • 439
  • 3
  • 10
  • I know it is filled with errors sir but i dont know pascal , just a little ruby. I am trying to help out my friend with his exams and he got this program to write. Thank you for your help – Robert Richards Mar 28 '15 at 02:54
  • @RobertRichards: Your title and question text say it's your assignment. Now it belongs to your friend? I smell copy/paste/pretend it's not my problem. – Ken White Mar 28 '15 at 03:13
  • I really didn't think it would make much a difference – Robert Richards Mar 28 '15 at 03:15
  • 1
    @RobertRichards Whoever wrote the code you posted looks like it was written in some other language besides Pascal, with a couple of Pascal things tossed in. Your friend needs to go through an elementary Pascal tutorial before attempting to write a Pascal program. – lurker Mar 28 '15 at 14:06
  • @lurker He doesnt know any languages and a beginner in Pascal, i don't know pascal but he says his teacher didnt prepare him much please help he needs it for monday – Robert Richards Mar 28 '15 at 14:07
  • @RobertRichards seriously, short of someone here just doing his assignment for him (which, hopefully, they have enough sense not to do) the best help in this case would be for him to learn the basics of Pascal via tutorial or book first. Otherwise, this will be a tedious line by line exercise of correcting Pascal language syntax and semantics. – lurker Mar 28 '15 at 14:10
  • @lurker Okay thank you can you please just point out his problems and i let him fix them – Robert Richards Mar 28 '15 at 14:11
  • 2
    @RobertRichards I suspect the teacher expects the students to spend a little time on their own to learn the language syntax since there's a lot of free information available to do so. Have him spend an hour or so studying [this Pascal tutorial](http://www.tutorialspoint.com/pascal/pascal_program_structure.htm). From that he should be able to fix most of the problems. If there are remaining stickier issues, they can be asked here. – lurker Mar 28 '15 at 14:21
  • @RobertRichards: Then tell your "friend" that he should have stayed awake in class. He should ask the teacher for help. This is an effort by you (or your "friend") to get us to do the assignment for you. – Ken White Mar 28 '15 at 23:21
  • i might help, but his code has too many errors, he got even lexical errors... he is not familiar with pascal at all. this looks more like basic. – Jorge Aldo Mar 28 '15 at 23:26