Nik22Dec wrote:BillyBoyo wrote:Expand on the previous solution you were given. Two-dimensional table, using customer-id converted to suitable index/subscript. flush/initialise table on change of customer-id. don't forget to do the last cutsomer-id flushing.

What Billy has proposed is absolutely corect. But, in case if you want to retain the entire data read till you exit the program, you can use an additional one-dimensional array to store the conumer-id & a two-dimensional array to compute the total expenditure of that consumer in a given month. Both the arrays will store corresponding information at the same index. For e.g. -

Array 1 - Row 1 - Cons 1

Array 2 - Row 1/Column1 - Total Exp. by Cons 1 in Jan

Array 2 - Row 1/Column2 - Total Exp. by Cons 1 in Feb

Array 2 - Row 1/Column3 - Total Exp. by Cons 1 in Mar & so on.

Thanks & Regards,

Nikhil

Thanks once again Billy. That's exactly what my point was when I wrote the above given approach. In my approach, the table would never be sparsely populated. Please find below an illustration.

Table 1 - Pos. 1 - Cons 1

Table 2 - Pos. 1/1 - Total Exp. by Cons 1 in Jan

Table 2 - Pos. 1/2 - Total Exp. by Cons 1 in Feb

Table 2 - Pos. 1/3 - Total Exp. by Cons 1 in Mar & so on.

Table 1 - Pos. 2 - Cons 134

Table 2 - Pos. 2/1 - Total Exp. by Cons 134 in Jan

Table 2 - Pos. 2/2 - Total Exp. by Cons 134 in Feb

Table 2 - Pos. 2/3 - Total Exp. by Cons 134 in Mar & so on.

Table 1 - Pos. 3 - Cons 1000000

Table 2 - Pos. 3/1 - Total Exp. by Cons 1000000 in Jan

Table 2 - Pos. 3/2 - Total Exp. by Cons 1000000 in Feb

Table 2 - Pos. 3/3 - Total Exp. by Cons 1000000 in Mar & so on.

Using a simple SEARCH, you can find the index value of any consumer id in Table 1 & corresponding expenditure details in Table 2.

In this case, the table would never contain an unwanted details.Doeas that make sense to you now.

Thanks & Regards,

Nik