Help Me Make My Pascal Program Display Multiple Names Which Were Entered Plz.
Posted
by Sketchie
on Stack Overflow
See other posts from Stack Overflow
or by Sketchie
Published on 2010-03-16T23:59:09Z
Indexed on
2010/03/17
0:01 UTC
Read the original article
Hit count: 170
Hey,Guys I'm having trouble displaying names using arrays in my Pascal program. But first heres the question I'm writing the program to answer :
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.
And here's what I've done so far(It's a bit messy):
program Maqueprgrm;
uses wincrt;
type
names=array [1..30]of string;
var
name:string;
s1_nms:names;
s2_nms:names;
s3_nms:names;
s4_nms:names;
s5_nms:names;
amt_paid:integer;
stop,x,full,ins,ttl1,ttl2,ttl3,ttl4,ttl5,sec_1,sec_2,sec_3,sec_4,sec_5,sec:integer;
begin
stop := 0;
writeln ('To Begin Data Collecting Section Press 1, To End Press 0');
readln(stop);
while stop <>0 do
begin
for x:= 1 to 30 do
x:= x+1;
writeln ('Please Enter The Name of Masquerader.');
readln (name);
writeln ('Please Enter The Amount Paid For Costume.');
readln (amt_paid);
IF amt_paid = 144 THEN Begin
full:=full+1; {people who paid in full + 1}
sec_1:=sec_1+1; {people in this section + 1}
ttl1:= ttl1+amt_paid; {total money earned in this section + amount person paid}
s1_nms[x]:= name; {People's names in this section plus current entry's name}
End else
IF amt_paid = 184 then Begin
ins:=ins+1;
sec_1:=sec_1+1;
ttl1:=ttl1+amt_paid;
s1_nms[x]:= name;
end else
IF amt_paid = 198 then Begin
full:=full+1;
sec_2:=sec_2+1;
ttl2:=ttl2+amt_paid;
s2_nms[x]:= 'name';
end else
IF amt_paid = 153 then Begin
ins:=ins+1;
sec_2:=sec_2+1;
ttl2:=ttl2+amt_paid;
s2_nms[x]:= 'name';
end else
IF amt_paid = 264 then Begin
full:=full+1;
sec_3:=sec_3+1;
ttl3:=ttl3+amt_paid;
s3_nms[x]:= 'name';
end else
IF amt_paid = 322 then Begin
ins:=ins+1;
sec_3:=sec_3+1;
ttl3:=ttl3+amt_paid;
s3_nms[x]:= 'name';
end else
IF amt_paid = 315 then Begin
full:=full+1;
sec_4:=sec_4+1;
ttl4:=ttl4+amt_paid;
s4_nms[x]:= 'name';
end else
IF amt_paid = 402 then Begin
ins:=ins+1;
sec_4:=sec_4+1;
ttl4:=ttl4+amt_paid;
s4_nms[x]:= 'name';
end else
IF amt_paid = 382. then Begin
ins:=ins+1;
sec_4:=sec_4+1;
ttl4:=ttl4+amt_paid; s4_nms[x]:= 'name';
end else IF amt_paid = 488 then Begin ins:=ins+1; sec_5:=sec_5+1; ttl5:=ttl5+amt_paid;
s5_nms[x]:= 'name';
end else begin
Writeln ('Invalid Entry');
For x:= 1 to 30 do
end;
writeln (' To Enter More Data Press 1, To Print Data and Calculations Press 0');
Readln (stop);
End;
writeln ('For Information on Sections Press 1, 2, 3, 4, or 5 Respectively');
Readln (sec);
IF Sec= 1 THEN Begin
for x:= 1 to 30 do;
begin
writeln ('The Number of Revelers in This Section is ',Sec_1,'.');
Writeln ('The Number of Revelers in the Band Who Paid in Full Is ', Full,'.');
Writeln ('The Number of Revelers in the Band Who Paid in Installments is ', Ins ,'.');
Writeln ('The Names of Revelers in This Section is ', S1_Nms[x], '.');
Writeln ('The Total Amount Collected By This Section Is ', Ttl1, '.');
End;
end else
IF Sec= 2 THEN Begin
For x:= 1 to 30 do begin
Writeln ('The Number of Revelers in This Section is ', Sec_2,'.');
Writeln ('The Number of Revelers in the Band Who Paid in Full Is ', Full,'.');
Writeln ('The Number of Revelers in the Band Who Paid in Installments is ', Ins ,'.');
Writeln ('The Names of Revelers in This Section is ', S2_Nms[x] ,'.');
Writeln ('The Total Amount Collected By This Section Is ', Ttl2, '.');
End;
End else
IF Sec= 3 THEN Begin
For x:= 1 to 30 do
begin
writeln ('The Number of Revelers in This Section is ', Sec_3,'.');
Writeln ('The Number of Revelers in the Band Who Paid in Full Is ', Full,'.');
Writeln ('The Number of Revelers in the Band Who Paid in Installments is ', Ins ,'.');
Writeln ('The Names of Revelers in This Section is ', S3_Nms[x] ,'.');
Writeln ('The Total Amount Collected By This Section Is ', Ttl3, '.'); End;
End else
IF Sec= 4 THEN Begin
For x:= 1 to 30 do
begin
writeln ('The Number of Revelers in This Section is ', Sec_4,'.');
Writeln ('The Number of Revelers in the Band Who Paid in Full Is ', Full,'.');
Writeln ('The Number of Revelers in the Band Who Paid in Installments is ', Ins, '.');
Writeln ('The Names of Revelers in This Section is ', S4_Nms [x],'.');
Writeln ('The Total Amount Collected By This Section Is ', Ttl4 ,'.');
End;
End else
IF Sec= 5 THEN Begin
For x:= 1 to 30 do
begin
writeln ('The Number of Revelers in This Section is ', Sec_5,'.');
Writeln ('The Number of Revelers in the Band Who Paid in Full Is ', Full,'.');
Writeln ('The Number of Revelers in the Band Who Paid in Installments is ', Ins, '.');
Writeln ('The Names of Revelers in This Section is ', S5_Nms[x], '.');
Writeln ('The Total Amount Collected By This Section Is ', Ttl5 ,'.');
End;
End else BEGIN
Writeln ('Invalid Entry. For Information on Sections Press 1, 2, 3, 4, or 5 Respectively. ');
End;
end.
The result I keep getting is that for the names in the section it is only the name of the last person entered that is displayed. For example it would display:
The number of revelers in this section is 2
The number of revelers in the band who paid in full is 2 {Band is the whole thing divided into 5 section}
The number of revelers in the band who paid in installments is 0
The names of revelers in this section is Amy
Total amount collected by this section is 288
So yea, the program only displays "Amy" even though I entered more than 1 name. Do you guys know how to fix it also if it's not asking too much could you help me to make a while loop for the last portion of the program so that after the user sees the info for a section he can see another section.
It sucks that I've been working on it for a while but if it doesn't run properly tomorrow I'll fail.
Help would be greatly appreciated and responses are welcome anytime cause i'll be up anyway.
P.S. Sorry for the long post.
© Stack Overflow or respective owner