1. for loop help

I am having trouble doing this problem. It is:
"write a program that asks the user to enter a list of integers. The program will then determine the largest value and the number of times it was entered.
-the user will first enter how many numbers the list contains.
-use a for loop to find the maximum value and the number of times it was entered"

This is what I have done. I cant seem to figure out how to count how many times the maximum value has been entered.

Code:
```#include <stdio.h>
#include <limits.h>

int main()
{

int num, num2, max;
int counter;
int counter2=0;

max = INT_MIN;

printf ("Enter the number of elements in this list: ");
scanf("%d",&num);
printf ("Enter the elements in this list: \n");

for(counter=1;counter<=num;counter++)
{

scanf ("%d",&num2);

if(num2=num2)
{
counter2++;

}

if(num2>max)
{
max = num2;
}

}

printf ("\nThe maximum number is %d and it was entered %d times\n",max, counter2);

return 0;
}```

2. Alright, so basically:
If our inputted number (num2) is equal to max (remember, conditional equality is == not =), we increase counter2 by 1. If we have a new maximum, then we set counter2 to 1 (Because the previous value wasn't the real maximum, and we now have a new maximum, with one occurance).
There's no real reason to initialize counter2 to 0 initially using this method, by the way.

3. So from what you just said, I should have three if statements, something like this?

if(num2>max)
{
max = num2;
}
if(max>num2)
{
counter2=1;
}
if(num2=max)
{
counter2++;
}

but in what order?

4. You're over-thinking the problem (which is common, btw). Think of it this way:

I hand you melons, one at a time. You need to pick out the largest melon size, and how many of them there are in that same size.

How would you do that?
Code:
```if(I give you a bigger size melon than the previous maximum size)
You have a new maximum size.
You have one of them
end if.

If(I give you another melon which is the maximum size)
You have one more maximum size melon
end if```
It's just that simple.

5. Originally Posted by zfite
So from what you just said, I should have three if statements, something like this?

but in what order?
First of all,
if(num2=max) is not the same as if(num2==max)!! The first one will set num2 to max, and then return max which evaluates to true (0 = false, not 0 = true in if statements). Completely different behavior.
Also, you have too many if statements. You only need the if(num2==max) and your original. Why would you reset the counter when you find a number *smaller* than the max? That doesn't make sense. You reset the counter to 1 when you find a number *bigger* than the max.
And logically, your if(num2==max) should be before the if(num2>max), because if it wasn't, you would get a new max, set the counter to 1, and then increase it by 1 (when we only have 1 occurance!), thus you'd go one over your actual answer.

Adak's psuedocode is what I'm trying to express, although in this case, the if statement's order matters, and your order would be the opposite of his.

6. Thanks, I got it.