views:

73

answers:

3

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):

A: 

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.

Pestilence
K.Thanks I'll try what you said but will it fix the names problem?
Sketchie
Eventually... :)
Pestilence
A: 

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.

Kirk Broadhurst
Thanks I'll try then report back.
Sketchie
I tried what you said but the output is mostly gaps.
Sketchie
could I get more answers please?
Sketchie
A: 

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.

Saladin Akara