Is it possible to print out an array in parts. For example you loop an array to check for 5 different things in an array. Can you subgroup the array with printing it. (eg. 1-5(sect1) 6-7(sect2)8-10(sect3)
what would I need to do: I know I can use a nested if to check, but I am having a problem printing the data in sub groups.
Tell me how anyone!
Can you show a little more of what you have now? The short answer is "yes", but it's not clear to me where you're having an issue. You just need 3 for loops (not nested).
this is the code I am working with. Now a college of mind did the same program and used 10 arrays. I think there is an easier way.
But I am getting trouble with getting it to work. Maybe I need to change my stategy abit
Code:Program CarnivalBandSectiondata(INPUT,OUTPUT); {DECLARING OF ALL DATA TYPES} VAR FAmnt:array[1..13] OF REAL; { declares cost array} {MasName:array[1..13] OF STRING[30];declares name array} Sn,Count :INTEGER; (*totnums*){declares the interger variables} FAmnt,totAmt,SecCP1,SecCP2,totnums: Real; { declares the real variables} (*Constants to declare the 5 cost for each section;*) Const {SecCP1=120;} {SecCP2=135; } {Change to your Cost} { SecCP3=185; } { SecCP4=220; } { SecCP5=265; } NumOfMasmem = 2; {number of Masqueraders in band} (*Names of masqueraders*) S1='BlueDevils'; {Change to your band names} S2='TriniRevellers'; { S3='RedDragons'; S4='OrangeSky'; S5='IslandTribe'; } {this is to count members in sections} Procedure Introduction; (*Program description*) (**) Begin Writeln( ' Author: Loris Scobie'); Writeln( ' Date: March '); Writeln( ' What the program does'); end; (* Introduction*) Procedure StoreData; {DO MENU WITH MAIN PROGRAMS} Begin FOR Count := 1 TO NumOfMasmem DO Begin (* This accepts data on Masqueraders Name and Full Amount Paid*) Writeln (' Enter Masqueraders name',Count,':' ); Readln(Masname); Writeln; Writeln('The Prices for each section are 120,135,185,220,265'); Writeln; Writeln (' Enter the Full Amount Paid:' ); Readln(FAmnt[Count]); End;(*end for*) End; Procedure Section; (*This will determine what section Masqueraders belong to*) Begin SecCP1 := 120; SecCP2 := 135; Sn := 0; { While Count <= 5 do} {Begin} For Count := 1 to NumOfMasmem do Sn := Count + 1; If FAmnt[Sn] =SecCP1 then begin Writeln('Member of' ,S1); writeln(MasName, FAmnt[Sn] :7:2); totAmt := NumOfMasmem * FAmnt; Writeln('Total Amount in Section $', totAmt:7:2); totnums:= NumOfMasmem; Writeln('Total members in Section',S1,totnums:7:0); writeln ; readln; end; If FAmnt[Sn] =SecCP2 then begin Writeln('Member of' ,S2); writeln(MasName, FAmnt[Sn] :7:2); {Sn := Count + 1;} totAmt := NumOfMasmem * FAmnt; Writeln('Total Amount in Section $', totAmt:7:2); totnums:= NumOfMasmem; Writeln('Total members in Section',S2,totnums:7:0); writeln ; readln; end; {End;} {Begin} { While Count <= 5 do} {Begin For Count := 1 to NumOfMasmem do writeln; readln End;} { End;} {Begin While Count <= 5 do Begin Writeln('Member of', S2, MasName[Count], FAmnt); Sn:=Count + 1; totAmt := Sn * FAmnt ; Writeln('Total Amount in Section $', totAmt); totnums:= Sn; Writeln('Total members in Section', S2 , Sn); End; End; If FAmnt =SecCP3 then Begin While Count <= 5 do Begin Writeln('Member of', S3, MasName[Count], FAmnt); Sn:= Count + 1 ; totAmt := Sn * FAmnt; Writeln('Total Amount in Section $', totAmt); totnums:= Sn; Writeln('Total members in Section', S3 , Sn); End; End; If FAmnt =SecCP4 then Begin While Count <= 5 do Begin Writeln('Member of', S4, MasName[Count], FAmnt); Sn:= Count + 1; totAmt := Sn * FAmnt; Writeln ('Total Amount in Section $', totAmt); totnums:= Sn; Writeln ('Total members in Section', S4, Sn); end; End; If FAmnt =SecCP5 then Begin While Count <= 5 do Begin Writeln('Member of', S5, MasName[Count], FAmnt); Sn:=Count + 1; totAmt := Sn * FAmnt; Writeln('Total Amount in Section $', totAmt ); totnums:= Sn; Writeln('Total members in Section', S5 ,Sn); End; End;} end; Begin Introduction; StoreData; Section; End. {Procedure Calculations; (*this will calculate the full amount for each section 1 - 5*) (*this will aslo calculate the total amount of people in each section*) (* 1. Read Name 2. Read Full Amount Paid 3. Match Full Amount Paid to sections(5) to determine section. Validate payment per section. 4. Count number of Masqueraders that paid in each section. 5. Calculate the total payments for each section *) Begin End;} {Procedure PrintInfo; (*Print the names of the masqueraders and their sections which paid in full*) (*Print a list of section and total person in each section*) (*Total amount of money paid in each section*) Begin Writeln(' Name of Masqueraters Section'); Writeln; Writeln( Masname, S1); End;}
Last edited by WingedPanther; 03-15-2010 at 05:35 PM.
Why not just do:
?Code:for i:= 1 to 5 do begin end; for i:= 6 to 7 do begin end; for i:= 8 to 10 do begin end;
Hmm!! That was a thought! I that case I would know that what I put in 1-5 and 6-8 would be different. But the case really was being able to pull out figures from the list of 1 - 10 and group them on the basis of difference of price in this case.
What are you thoughts with that happening then. I am forced to think go two dimensional arrays, but I do not want to do that just yet.
OK, I just reformatted your code so I can read it easier, and I think I see the trick. You don't need a 2d array, you need nested for loops. The outer loop would go through an array of bands, with the inner loop going through the array of prices and only printing them if it matches the parallel array for the band price.
Just a note: formatting matters. I'm posting the reformatted code here for reference.
Code:Program CarnivalBandSectiondata(INPUT,OUTPUT); {DECLARING OF ALL DATA TYPES} VAR FAmnt:array[1..13] OF REAL; { declares cost array} {MasName:array[1..13] OF STRING[30];declares name array} Sn,Count :INTEGER; (*totnums*){declares the interger variables} FAmnt,totAmt,SecCP1,SecCP2,totnums: Real; { declares the real variables} (*Constants to declare the 5 cost for each section;*) Const {SecCP1=120;} {SecCP2=135;} {Change to your Cost} {SecCP3=185;} {SecCP4=220;} {SecCP5=265;} NumOfMasmem = 2; {number of Masqueraders in band} (*Names of masqueraders*) S1='BlueDevils'; {Change to your band names} S2='TriniRevellers'; {S3='RedDragons'; S4='OrangeSky'; S5='IslandTribe';} {this is to count members in sections} Procedure Introduction; (*Program description*) Begin Writeln( ' Author: Loris Scobie'); Writeln( ' Date: March '); Writeln( ' What the program does'); end;(* Introduction*) Procedure StoreData; {DO MENU WITH MAIN PROGRAMS} Begin FOR Count := 1 TO NumOfMasmem DO Begin (* This accepts data on Masqueraders Name and Full Amount Paid*) Writeln (' Enter Masqueraders name',Count,':' ); Readln(Masname); Writeln; Writeln('The Prices for each section are 120,135,185,220,265'); Writeln; Writeln (' Enter the Full Amount Paid:' ); Readln(FAmnt[Count]); End;(*end for*) End; Procedure Section; (*This will determine what section Masqueraders belong to*) Begin SecCP1 := 120; SecCP2 := 135; Sn := 0; {While Count <= 5 do} {Begin} For Count := 1 to NumOfMasmem do Sn := Count + 1; If FAmnt[Sn] =SecCP1 then begin Writeln('Member of' ,S1); writeln(MasName, FAmnt[Sn] :7:2); totAmt := NumOfMasmem * FAmnt; Writeln('Total Amount in Section $', totAmt:7:2); totnums:= NumOfMasmem; Writeln('Total members in Section',S1,totnums:7:0); writeln ; readln; end; If FAmnt[Sn] =SecCP2 then begin Writeln('Member of' ,S2); writeln(MasName, FAmnt[Sn] :7:2); {Sn := Count + 1;} totAmt := NumOfMasmem * FAmnt; Writeln('Total Amount in Section $', totAmt:7:2); totnums:= NumOfMasmem; Writeln('Total members in Section',S2,totnums:7:0); writeln ; readln; end; {End;} {Begin} { While Count <= 5 do} {Begin For Count := 1 to NumOfMasmem do writeln; readln End;} { End;} {Begin While Count <= 5 do Begin Writeln('Member of', S2, MasName[Count], FAmnt); Sn:=Count + 1; totAmt := Sn * FAmnt ; Writeln('Total Amount in Section $', totAmt); totnums:= Sn; Writeln('Total members in Section', S2 , Sn); End; End; If FAmnt =SecCP3 then Begin While Count <= 5 do Begin Writeln('Member of', S3, MasName[Count], FAmnt); Sn:= Count + 1 ; totAmt := Sn * FAmnt; Writeln('Total Amount in Section $', totAmt); totnums:= Sn; Writeln('Total members in Section', S3 , Sn); End; End; If FAmnt =SecCP4 then Begin While Count <= 5 do Begin Writeln('Member of', S4, MasName[Count], FAmnt); Sn:= Count + 1; totAmt := Sn * FAmnt; Writeln ('Total Amount in Section $', totAmt); totnums:= Sn; Writeln ('Total members in Section', S4, Sn); end; End; If FAmnt =SecCP5 then Begin While Count <= 5 do Begin Writeln('Member of', S5, MasName[Count], FAmnt); Sn:=Count + 1; totAmt := Sn * FAmnt; Writeln('Total Amount in Section $', totAmt ); totnums:= Sn; Writeln('Total members in Section', S5 ,Sn); End; End;} end; Begin Introduction; StoreData; Section; End. {Procedure Calculations; (*this will calculate the full amount for each section 1 - 5*) (*this will aslo calculate the total amount of people in each section*) (* 1. Read Name 2. Read Full Amount Paid 3. Match Full Amount Paid to sections(5) to determine section. Validate payment per section. 4. Count number of Masqueraders that paid in each section. 5. Calculate the total payments for each section *) Begin End;} {Procedure PrintInfo; (*Print the names of the masqueraders and their sections which paid in full*) (*Print a list of section and total person in each section*) (*Total amount of money paid in each section*) Begin Writeln(' Name of Masqueraters Section'); Writeln; Writeln( Masname, S1); End;}
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks