Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

Posted on 2000-03-23
Medium Priority
448 Views
I'm working on a little program teaching myself about arrays but have come to a stop at the present.  I have writtern and compiled the progame but for some reason that I just can not see not all of the information held within an array is being displayed.  The program is based on a billing system with 5 customer over 3 months, if you can help me I would be most grateful :0)

Program Electricty_Bill;
Uses Wincrt;

Var Units,A,B:Integer;
Var UnitCharge,SubTotal,VAT:Real;
Var Month1:Array[1..5] OF Integer;
Var Month2:Array[1..5] OF Integer;
Var Month3:Array[1..5] OF Integer;
Var CustName:Array[1..5] OF String;
Var CustNo:Array[1..5] Of Real;
Var Total1:Array[1..5] OF Real;
Var Total2:Array[1..5] OF Real;
Var Total3:Array[1..5] OF Real;

Function Charge (Units:Integer):Real;
Begin
CASE Units OF
0..300     : UnitCharge:=0.09;
301..500   : UnitCharge:=0.08;
501..800   : UnitCharge:=0.07;
801..1000  : UnitCharge:=0.06;
ELSE         UnitCharge:=0.05;
end;
Charge:=((Units*UnitCharge)+12.57)*1.175;
End;

Procedure Collect_Data;
begin
Write('Enter First Months Amount Of Units Use...>>');
Write('Enter Second Months Amount Of Units Used...>>');
Write('Enter Third Months Amount Of Units Used...>>');
Clrscr;
end;

Procedure Calculate_Charge;
begin
For B:= 1 To 5 Do
Total1[B]:=Charge(Month1[B]);
Total2[B]:=Charge(Month2[B]);
Total3[B]:=Charge(Month3[B]);
end;

Procedure Display_Output;
Begin
Writeln('Customer Number>>',CustNo[1]:4:0,'Customer Name>>',CustName[1]);
Writeln('Total Units Used>>',Month1[1],'Total Charge>>',Total1[1]:4:2);
Writeln('Total Units Used>>',Month2[1],'Total Charge>>',Total2[1]:4:2);
Writeln('Total Units Used>>',Month3[1],'Total Charge>>',Total3[1]:4:2);
Writeln('');
Writeln('Customer Number>>',CustNo[2]:4:0,'Customer Name>>',CustName[2]);
Writeln('Total Units Used>>',Month1[2],'Total Charge>>',Total1[2]:4:2);
Writeln('Total Units Used>>',Month2[2],'Total Charge>>',Total2[2]:4:2);
Writeln('Total Units Used>>',Month3[2],'Total Charge>>',Total3[2]:4:2);
Writeln('');
Writeln('Customer Number>>',CustNo[3]:4:0,'Customer Name>>',CustName[3]);
Writeln('Total Units Used>>',Month1[3],'Total Charge>>',Total1[3]:4:2);
Writeln('Total Units Used>>',Month2[3],'Total Charge>>',Total2[3]:4:2);
Writeln('Total Units Used>>',Month3[3],'Total Charge>>',Total3[3]:4:2);
Writeln('');
Writeln('Customer Number>>',CustNo[4]:4:0,'Customer Name>>',CustName[4]);
Writeln('Total Units Used>>',Month1[4],'Total Charge>>',Total1[4]:4:2);
Writeln('Total Units Used>>',Month2[4],'Total Charge>>',Total2[4]:4:2);
Writeln('Total Units Used>>',Month3[4],'Total Charge>>',Total3[4]:4:2);
Writeln('');
Writeln('Customer Number>>',CustNo[5]:4:0,'Customer Name>>',CustName[5]);
Writeln('Total Units Used>>',Month1[5],'Total Charge>>',Total1[5]:4:2);
Writeln('Total Units Used>>',Month2[5],'Total Charge>>',Total2[5]:4:2);
Writeln('Total Units Used>>',Month3[5],'Total Charge>>',Total3[5]:4:2);
end;

Begin
For B:=1 To 5 Do
For A:=1 To 5 Do
Begin
Collect_Data;
Calculate_Charge;
end;
Display_Output;
end;
End.

0
Question by:3_Armed_Human
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 12

Expert Comment

ID: 2650883

Instead of making three arrays called Month1, Month2 and Month3, You can make one 2Dimensional array called months...

Like this,
var Months : array[1..3,1..5] of integer;

and then you use it like this: Months[2,1] := 10;
or: Months[CustomerNumber,MonthNumber] := 10;

The use of records and 2D arrays could make your example much smaller.
0

LVL 12

Expert Comment

ID: 2650893
oh... sorry,
Months[CustomerNumber,MonthNumber] := 10; should be the opposite...

Months[MonthNumber,CustomerNumber] := 10;
is what i meant!
0

LVL 49

Expert Comment

ID: 2652487
Here's part of the problem I think - still checking code.  You have missed out a begin and end

Procedure Calculate_Charge;
begin
For B:= 1 To 5 Do
begin
Total1[B]:=Charge(Month1[B]);
Total2[B]:=Charge(Month2[B]);
Total3[B]:=Charge(Month3[B]);
end;
end;
0

Expert Comment

ID: 2652687
Set a variable called index as an integer in the chosen procedure.  Then when you want to use the infomation from the array you can type

WITH Month1[index] Do
Etc
Etc
Ect

I dont know why this changes things, but it does.
0

LVL 49

Accepted Solution

dbrunton earned 200 total points
ID: 2653973
This works.  Code has been cleaned up greatly.  Major error.  Redundant for loop in original code.

for loop1
for loop2

Error.  Redundant variable B.  B is not needed.
Use variable A as index in procedures.

Program Electricty_Bill;
{ Uses Wincrt; }

const
Max = 5;

Var
A : Integer;
UnitCharge, SubTotal, VAT : Real;
Month1 : Array[1..Max] OF Integer;
Month2 : Array[1..Max] OF Integer;
Month3 : Array[1..Max] OF Integer;
CustName : Array[1..Max] OF String;
CustNo : Array[1..Max] Of Real;
Total1 : Array[1..Max] OF Real;
Total2 : Array[1..Max] OF Real;
Total3 : Array[1..Max] OF Real;

Function Charge(Units : Integer) : Real;
Begin
CASE Units OF
0..300     : UnitCharge:=0.09;
301..500   : UnitCharge:=0.08;
501..800   : UnitCharge:=0.07;
801..1000  : UnitCharge:=0.06;
ELSE
UnitCharge := 0.05;
end;
Charge := ((Units*UnitCharge)+12.57)*1.175;
End;

Procedure Collect_Data;
begin
Write('Enter First Months Amount Of Units Use...>>');
Write('Enter Second Months Amount Of Units Used...>>');
Write('Enter Third Months Amount Of Units Used...>>');
;
end;

Procedure Calculate_Charge;
begin
Total1[A] := Charge(Month1[A]);
Total2[A] := Charge(Month2[A]);
Total3[A] := Charge(Month3[A]);
end;

Procedure Display_Output;
Begin
Writeln('Customer Number>>',CustNo[A]:4:0,'Customer Name>>',CustName[A]);
Writeln('Total Units Used>>',Month1[A],'Total Charge>>',Total1[A]:4:2);
Writeln('Total Units Used>>',Month2[A],'Total Charge>>',Total2[A]:4:2);
Writeln('Total Units Used>>',Month3[A],'Total Charge>>',Total3[A]:4:2);
Writeln('');
end;

Begin
For A := 1 To Max Do
Begin
Collect_Data;
Calculate_Charge;
end;
For A := 1 to Max Do
Display_Output;
End.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, WatchGuard's Director of Security Strategy and Research Teri Radichel, takes a look at insider threats, the risk they can pose to your organization, and the best ways to defend against them.
On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrasâ€¦
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastrâ€¦
###### Suggested Courses
Course of the Month11 days, 11 hours left to enroll