In an array of temperatures, each day for a whole month:
int april[31];
int days;
int i=0, maxpos, max;
printf("How many days are in this month?\n");
scanf("%d", &days);
if (days < 0)
printf("Unreceivable number of days\n");
else{
for(i=0; i <= days-1; i++)
{
printf("Day %d: Give today's temperature: \n", i+1);
scanf("%d", &april[i]);
}
for(i=0; i <= days-1; i++)
printf("%Day %d = %d\n", i+1, april[i]);
maxpos=0;
max = april[0];
for(i=0; i <= days-1; i++)
{
if (april[i] > max)
{
max = april[i];
maxpos = i;
}
}
printf("The maximum temperature of the month is %d on Day %d of the month\n", max, maxpos+1);
}
the programme has to print out the maximum temperature and the day that happened, like:
The maximum temperature is 42 on Day 2 of the month
But, what if two days of the month have the same temperature? I guess the screen will show the first/older temperature:
Day 1 = 23
Day 2 = 33
Day 3 = 33
Day 4 = 30
Day 5 = 33
in this case, Day 2.
How can I make it print the latest, most recent maximum temperature (Day 5 in the example above)?
int month[31];would be less confusing.for(i=0; i<=days-1; i++)please code asfor(i=0; i<days; i++). It's clearer, and if you continue your way, eventually you'll fall into a hole when you haveunsigned days = 0;which can easily happen when analysing data.