Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Can you help me figure our why I am getting Fatal error ";" expected but Else found at line 34? Please and thanks.

0 votes
asked May 9 by Neesha Gangar (120 points)
{
SBA 2022 - Car Show}

program CarShow;

Var CarModel:string;
CarCounter1, CarCounter2, CarCounter3:integer;
RentalFee, TotalRentalFee1, TotalRentalFee2, TotalRentalFee3:real;

Const RentalFee1 = 1500;
RentalFee2 = 2000;
RentalFee3 = 2500;

begin
CarCounter1:= 0;
CarCounter2:= 0;
CarCounter3:= 0;
TotalRentalFee1:= 0;
TotalRentalFee2:= 0;
TotalRentalFee3:= 0;
RentalFee:= 0;

writeln ('Please enter the model of car.');
readln (CarModel);

If (CarModel='Kia Celtos')
     then Begin RentalFee:= RentalFee1;
CarCounter1:= CarCounter1+1;
TotalRentalFee1:= TotalRentalFee1+RentalFee; End Else Begin
If (CarModel='Kia Sonet')
     then RentalFee:= RentalFee2;
CarCounter2:= CarCounter2+1;
TotalRentalFee2:= TotalRentalFee2+RentalFee; End Else Begin
If (CarModel='Kia Forte')
     then RentalFee:= RentalFee3;
CarCounter3:= CarCounter3+1;
TotalRentalFee3:= TotalRentalFee3+RentalFee; End Else Begin
Writeln ('Sorry incorrect entry') end.

2 Answers

0 votes
answered May 11 by Ema Srbinovska (140 points)
you probably need to add a ; at the end of the sentence of line 34
0 votes
answered May 11 by Peter Minarik (53,530 points)

You should get your code formatting and indentation right so you'd see what line of code belongs where. This way you could easier match the Begins and Ends, etc.

I've fixed up the code for you:

program CarShow;

Var
    CarModel : string;
    CarCounter1, CarCounter2, CarCounter3 : integer;
    RentalFee, TotalRentalFee1, TotalRentalFee2, TotalRentalFee3 : real;

Const
    RentalFee1 = 1500;
    RentalFee2 = 2000;
    RentalFee3 = 2500;

Begin
    CarCounter1 := 0;
    CarCounter2 := 0;
    CarCounter3 := 0;
    TotalRentalFee1 := 0;
    TotalRentalFee2 := 0;
    TotalRentalFee3 := 0;
    RentalFee := 0;
    
    writeln ('Please enter the model of car.');
    readln (CarModel);
    
    If (CarModel = 'Kia Celtos') Then
    Begin
        RentalFee := RentalFee1;
        CarCounter1 := CarCounter1 + 1;
        TotalRentalFee1 := TotalRentalFee1+RentalFee;
    End
    Else If (CarModel = 'Kia Sonet') Then
    Begin
        RentalFee := RentalFee2;
        CarCounter2 := CarCounter2 + 1;
        TotalRentalFee2 := TotalRentalFee2 + RentalFee;
    End
    Else If (CarModel = 'Kia Forte') Then
    Begin
        RentalFee := RentalFee3;
        CarCounter3 := CarCounter3 + 1;
        TotalRentalFee3 := TotalRentalFee3+RentalFee;
    End
    Else
    Begin
        Writeln ('Sorry incorrect entry')
    End
End.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...