Reputation: 47
The program is input the number of equipments rented and the cost paid. If equipment is damaged there's an additional cost. And data entered should be outputted on the screen.
When I enter 2 for damage equipment and it ask to enter the original the program it stops; however result is executed when I input 1; but for the number of equipments it accepts 0 and when I'm prompted to enter the number of equipments return again it accepts another number; I can't seem to figure out the issue.
This is the entire program that I have written.
Program Rental_info;
CONST
Flaterate= 100000;
Penalty= 0.05;
Var
client_name, ID_number: array[1..1000] of string;
Total_equiprented, equip_return,equipcondition: array [1..1000]of integer;
Total_paid, Balance, Additional_cost, orig_cost:array[1..1000]of real;
num_of_clients,option,x,y,G,s, B, A, Clientaddcost_count: integer;
Total_amt_out,Total_amt_received,Total_add_cost:real;
Begin
num_of_clients:=0 ;
x:=0;
y:=0;
s:=0;
B:=0;
A:=0;
Total_amt_out:=0;
Total_amt_received:=0;
Total_add_cost:=0;
For A:=1 to num_of_clients DO
Begin
Total_equiprented[A]:=0;
Total_paid[A]:=0;
Balance[A]:=0;
Additional_cost[A]:=0;
Orig_cost[A]:=0;
End;
option:=0;
while option<2 do
begin
Writeln('Do you wish to add a client?') ;
Writeln('Enter 1 for yes and 2 for no');
Readln(option);
IF (option = 1) THEN
Begin
Writeln('****WELCOME TO SSC Agricultural Rental Enterprise Records****');
Writeln('Please enter the total number of rental clients') ;
Readln(num_of_clients) ;
// For s:=1 to num_of_clients DO writeln(s);
For x:=1 to num_of_clients DO
Begin
Writeln('Please enter rental client name: ') ;
Readln(client_name[x]);
Writeln('Please enter client ID number: ');
Readln(ID_number[x]);
Writeln('Please enter the amount of equipment rented: ');
Readln(Total_equiprented[x]);
While Total_equiprented[x]>5 Do
begin
Writeln('Please enter a smaller amount of equipment rented, amount should be <5!');
Readln(Total_equiprented[x]);
End;
Writeln('Please enter amount paid for rented equipment: ');
Readln(Total_paid[x]);
end;
For y:=1 to num_of_clients DO
Begin
Balance[y]:= Flaterate-Total_paid[y]
End;
For s:=1 to num_of_clients DO
Begin
Writeln('Please select overall condition of equipment: ');
Writeln('1-Good');
Writeln('2-Damage') ;
//Writeln('Type overall condition of the equipment');
Readln(equipcondition[s]);
Writeln('Please enter amount of equipment returned');
Readln(equip_return[s]);
If (equipcondition[s]=1) AND (equip_return[s]=Total_equiprented[s]) then
Begin
Additional_cost[s]:=0;
End
else if (equipcondition[s]=2) AND (equip_return[s]=Total_equiprented[s]) then
Begin
Writeln('Please enter the original cost for equipment');
Readln(orig_cost[s]);
//Writeln(orig_cost[s]);
Additional_cost[s]:= orig_cost[s]*Penalty;
End;
End;
For B:=1 to num_of_clients DO
Begin
Total_amt_out:= Total_amt_out + Balance[B];
Total_amt_received:= Total_amt_received + Total_paid[B];
Total_add_cost:= Total_add_cost + Additional_cost[B];
While Total_add_cost>0 Do
Begin
Clientaddcost_count:= Clientaddcost_count + 1;
End;
End;
For G:=1 to num_of_clients DO
Begin
Writeln('The client(s) with oustanding balances is/are ', client_name[B]);
Writeln('The total number of client(s) who are required to pay additional charges is/are ', Clientaddcost_count);
Writeln('The total payment received for rental equipment is ', Total_amt_received:0:2);
Writeln('The total payment outstanding for rental equipment is ', Total_amt_out:0:2);
Writeln('Client total additional amount to be collected for damaged equipment is ', Total_add_cost:0:2);
end;
end
else
Begin
Writeln ('****Thank you for contacting SSC AGRICULTURAL RENTAl ENTERPRISE, GOODBYE****');
Writeln;
Writeln;
Writeln('Press <Enter> To Quit...');
Readln;
End;
end;
End.
Upvotes: 0
Views: 107
Reputation: 80107
Your program enters in infinite loop when Total_add_cost
is non-zero here:
While Total_add_cost>0 Do
Begin
Clientaddcost_count:= Clientaddcost_count + 1;
End;
and you don't change Total_add_cost
inside the loop to stop it ever.
Reconsider this logic.
Upvotes: 1