how do i show the minimum after adding my arrays?

My objective here is to show the minimum which is the lowest after added my arrays. I havee 12 arrays and i have added them correspondingly by month. January arrays, feb arrays, march arrays ETC. Now the problem is, how do i compare this 12 arrays and then display the lowest or minimum among this 12 arrays?
The overall minimum? You could find the minimum at each array and then evaluate the overall minimum from all array's minimums.
@diddledidum

Hi. what do you mean by find minimum at each array?

my example..
Array1[]={23,22,44,22,33,44} ( Total = 188 )
Array2[]={23,22,44,22,33,45} ( Total = 189 )
Array3[]={23,22,44,22,33,46} ( Total = 190 )
Array4[]={23,22,44,22,33,47} ( Total = 191 )
Array5[]={23,22,44,22,33,48} ( Total = 192 )

So the minimum total array is the lowest which is 188 and i have to state the month.

or arrange from highest to lowest.
arrange from highest to lowest

You want to sort objects.

Sorting uses two operations:
* a test to see whether two objects are in the correct order
* a swap of values between two objects

You can sort separate variables, but the complexity of the code explodes if you have many variables (like the Array1..Array12). It is much easier to sort an array of objects.

In your case each object contains an array of integers and object A is greater than object B if the sum of the values in A's array is greater than the sum of the values in B's array.
closed account (48T7M4Gy)
My objective here is to show the minimum which is the lowest after added my arrays.


If I understand the OP correctly the problem can be looked at as follows:

1. there are 12 month arrays, each with a series of numbers, say, month_by_month_numbers[]

2. each of those array of numbers has a monthly total which can be put in another array of totals, say monthly_total[]

3.OP wants to find the minimum value contained within the monthly_total array.

All you have to do is keep the index numbers of the two arrays in sync so month_numbers[3] corresponds with monthly_total[3] and month[3] is "March" if you like. ( The names of the months are in a third and final array of strings. )

Getting the minimum is much less fiddly than sorting so avoid unless I've misunderstood OP.

So, add each set of monthly numbers and store result in a separate array
Then get the minimum value and index from the second array. :)
Last edited on
@kemort

I get what you mean. Thats what ive been trying to do. by adding the monthly total in another array. but how do i do that? how do i add my total Jan, Feb,March etc into monthly_total[] after ive automatically added it by computing? How do i add them into the monthly_total[] array?
closed account (48T7M4Gy)
For month = 3 for example, after adding up all the numbers for month[3] and let's say you call that sumTotal, you then write monthly_total[3] = sumTotal; Then you move on to the next month.

Also you are not making it crystal clear what you are trying to achieve so you should do it according to a pseudocode plan and in small pieces.

Do you know how to add up a series of numbers in an array?
Do you know how to make a new array and load numbers into it?
Do you know how to get the lowest number in an array of numbers?

If you don't answer 'Yes' to any of these then you need to revise and experiment using the tutorials for that part.

Show us you code as you go. :)
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/general/195694/
http://www.cplusplus.com/forum/general/195730/
Topic archived. No new replies allowed.