1. ## Finding the Mode

So i have yet ANOTHER lab due next week... This one calls for us to create a program that accepts inputs of only positive whole numbers, (if it is negative it will end the program and output ALL modes, meaning if there is more than one mode it needs to output the numbers that are all tied for the most used.) I know it has to use arrays in one way or another, but i am having a difficult time trying to figure out how to set this program up. I am really new to arrays so my ability to use conceptualize it in my head is weak. Can anyone help me plot what this program needs to do? obviously ill need a while loop with some conditions in it. But... past that, its over my head.

2. Well, perhaps you should figure out how to keep a count of the data points.

3. ## Well..

I believe i caught myself up a little bit on array's, so here is what i have so far... just need to find a way to create a loop that keeps track of when an integer is duplicated. and then outputting it, but im stuck.
Code:
```#include <FPT.h>
int main()
{
double n[1000],,i;
i=0;
n[i]=inD();
while(n>=0){
i=i+1;
n[i]=inD();
}
}```

4. Have you seen a frequency chart? They look like this:
Code:
```number  frequency
------  ---------
1         4
2         6
3         3
4        11
5         7```
How would you store that in an array?

5. I have never heard of a frequency chart before. Well i would know how to store the users input and keep track of the most frequently inputted number. But finding multiple modes if there is the same number? thats where i am confused.

6. That's why you can't just "keep track of the most frequently inputted number". You have to keep track of all the numbers and how often they occur.

7. Well, by performing the loop i have done there, isn't that keeping track of all the numbers by storing them into the values for i? Or is there another way i need to keep track of them?

8. If you can't find out how many 4's there are by saying frequency[4], you're not done yet.

9. is frequency a function? because we have not learned that yet. or is frequence a variable?

10. I was just using it as a variable name. (Obviously you can call it whatever you want; count is popular.)

And of course you knew that: anything followed by [brackets] is an array, while functions are followed by (parentheses).

11. Originally Posted by Lucid15
... if there is more than one mode it needs to output the numbers that are all tied for the most used.
You only want the "most used", or do you intend to output a list of duplicate modes, in descending order possibly?

12. I just need the mode of the inputted data set. So if there are 3 7's and 3 5's, i need it to output 7 AND 5.

13. Just the fact that a number is repeated matters? Then I would suggest that for every new number you are about to add, you simply loop through all existing numbers and see if it already exists. If yes, then print out that fact... and set a flag indicator (one for each number) so that you don't alert the user another time if that number comes up again. Add only unique numbers to the array.

14. So basically create two different arrays, one for storing ALL inputted values and one for storing DUPLICATE values? am i getting this right? if so, i think it makes sense. Then of course after they input a negative number it checks the duplicate array and then finds if any repeat and which one repeats the most, correct?

15. As long as every input number gets stored somewhere, I guess that will work. You might win simultaneous awards for most inefficient and most confusing, but that's neither here nor there.

Again, I don't see how storing the list of numbers could possibly be a good idea, since you need the counts of how often the numbers occur.