How do you display the month of the min value in an array?

Jul 22, 2016 at 5:47am
hi there,im just wondering how do you display the month of the min value in an array.
E.g:
void dispMin(void)
{

char input;
float Min;;
int j;



do{
printf("please select an option\n");
puts("A:1-room\n");
puts("B:2-Room\n");
puts("C:3-room\n");
puts("D:4-room\n");
puts("E:5-room\n");
puts("Q:Return to main menu");

input = _getch();
switch (input)
{
case 'a':case 'A':
printf("You have selected 1-room\n");
Min = rm1[0];
for (j = 0; j<5; j++)
{
if (rm1[j] < Min)
Min = rm1[j];
}
printf("The minimum is %.2f on the %dth month\n", Min, j);
for (j = 0; j<9; j++)
{
if (rm1[j] < 5)continue;
Min = rm1[j];
}
printf("The min is %.2f on the %dth month\n", Min, j);
for (j = 0; j < 12; j++)
{
if (rm1[j] < 9)continue;
Min = rm1[j];
}
printf("The min is %.2f on the %dth month\n", Min, j);

break;

So i got the min value however the month displayed is incorrect and im not sure how to display the corresponding month of the min value. Any ideas?
Last edited on Jul 22, 2016 at 12:36pm
Jul 22, 2016 at 5:49am
> Display the month of the min value in an array.
Can you clarify what you mean?
Jul 22, 2016 at 8:00am
Hi, for eg you declared a number of arrays as rm1[]={................} and you wanna find the min value and the number the min value is at (e.g rm1[]={5,2,3,4}) the second. so i need the loop to stop at rm1[1] and then display the number j (the month) exactly where the min value is found.

Sry english isnt my first language so please pardon my poor english.
Jul 22, 2016 at 12:36pm
Maybe telling the question will help ? Qn:Display 3 least minimum water consumption and corresponding months.
Topic archived. No new replies allowed.