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 :
And here's what I've done so far(It's a bit messy):
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 :
And here's what I've done so far(It's a bit messy):
Well, there are many problems. First off, you are double-incrementing in parts:
for x:= 1 to 30 do
x:= x+1; // it's already incremented above
You don't have separate variables for Full
and lns
for each section. I don't know if that's a problem. Also, your input data is important. Each amount value must be exact, otherwise it won't be recorded... so any deviations aren't recorded, if your input is wrong.
There's simply too much code to go through. More code reuse and a reposting is necessary.
You have
For x:=1 to 30 do
....
Writeln ('The Number of Revelers in the Band Who Paid in Full Is ', Full,'.');
Writeln ('The Names of Revelers in This Section is ', S4_Nms [x],'.');
which you can see will only ever output one name for each loop iteration. You'll also display the number of revellers for each iteration, and so forth. What you need to do is move the loop to only iterate over the name array, not the number of revellers and whether they paid etc.
Writeln ('The Number of Revelers in the Band Who Paid in Full Is ', Full,'.');
Write('The Names of Revelers in This Section is ');
For x:= 1 to 30 do
begin
if (S4_Nms[x] != '')
Write(S4_Nms[x];
endif
end
Forgive my poor attempt at Pascal.
I can't see the code that you originally included in your question, but here is an example for you:
Program OutPutArray;
Uses CRT;
Var
namesArray: array[1..5] of String;
loopcontrol: integer;
(* This code block will fill your array *)
Begin
for loopcontrol := 1 to 5 do
begin
Writeln('Input name ',loopcontrol);
readln(namesArray[loopcontrol]);
end;
(* This code block will output the contents of your array *)
for loopcontrol := 1 to 5 do
begin
writeln(namesArray[loopcontrol]);
end;
end.