int main() { const int SIZE = 100; int y[SIZE] = {}; int dup[SIZE] = {}; for (int i = 0; i <=100;++i){ cout << "Enter a value between 1-100 (Press -99 to stop): " << endl; cin >> y[i]; if (y[i] == -99) break; } cout << "The values entered are: " << endl; for (int i = 0; i < y[i];++i) cout<<y[i] << endl; return 0; }

# Help with displaying frequencies

Page 1 of 1## 9 Replies - 351 Views - Last Post: 07 November 2017 - 06:26 AM

### #1

# Help with displaying frequencies

Posted 06 November 2017 - 09:39 PM

My program is supposed to display the values of the numbers that the user entered, I have no problem with that. Where I'm having trouble is displaying the frequencies of all the values that are entered. Frankly, I have no idea where to start. Can someone please help me.

##
**Replies To:** Help with displaying frequencies

### #2

## Re: Help with displaying frequencies

Posted 06 November 2017 - 09:51 PM

It works when I run it.

Enter a value between 1-100 (Press -99 to stop):

1

Enter a value between 1-100 (Press -99 to stop):

2

Enter a value between 1-100 (Press -99 to stop):

3

Enter a value between 1-100 (Press -99 to stop):

-99

The values entered are:

1

2

3

I don't understand what problems you are talking about.

Enter a value between 1-100 (Press -99 to stop):

1

Enter a value between 1-100 (Press -99 to stop):

2

Enter a value between 1-100 (Press -99 to stop):

3

Enter a value between 1-100 (Press -99 to stop):

-99

The values entered are:

1

2

3

I don't understand what problems you are talking about.

### #3

## Re: Help with displaying frequencies

Posted 06 November 2017 - 09:56 PM

I need to display the frequencies of each value that is entered as well and I'm not sure where to start with that

### #4

## Re: Help with displaying frequencies

Posted 06 November 2017 - 10:19 PM

Well, think about what you need to do to accomplish that. One thing to think about is how you're going to store the counts. What kinds of things in the language would be useful for this? Also, if this is an assignment, what are you allowed to use? The other thing to think about is mechanically how you go about performing this task. If I gave you a list of numberstuff and asked you to count the times each number occurred, how would you do it?

### #5

## Re: Help with displaying frequencies

Posted 06 November 2017 - 11:06 PM

Cumulative frequency

https://en.wikipedia...quency_analysis

is a branch of statistics

from the wiki the equation is

Where M

From your point of view best to employ a Table.

A table can be constructed from a matrix

A matrix is another word for an array.

so your input range is 1 to 100 so there is your first part of your array.

and you could use a struct along with a std::vector to do this dynamically

struct example

and you would initialise the vector thus

now it is just a matter of inputting the numbers into the frequency part of the vector

https://en.wikipedia...quency_analysis

is a branch of statistics

from the wiki the equation is

Where M

_{Xr}is the total of the number added together and N is the amount itselfFrom your point of view best to employ a Table.

A table can be constructed from a matrix

A matrix is another word for an array.

so your input range is 1 to 100 so there is your first part of your array.

and you could use a struct along with a std::vector to do this dynamically

struct example

struct Table { int value; int frequency=0; };

and you would initialise the vector thus

std::vector<Table> results; Table input; for(int i= 0; i<RANGE; i++) { input.frequency=0; input.value = i+1; results.push_back(input); }

now it is just a matter of inputting the numbers into the frequency part of the vector

if(answer!=-99) results[answer-1].frequency = results[answer-1].frequency+1;

This post has been edited by **snoopy11**: 06 November 2017 - 11:59 PM

Reason for edit:: fixed sub tag

### #6

## Re: Help with displaying frequencies

Posted 07 November 2017 - 12:12 AM

where would I place the struct and vector in my code? Sorry, my professor refuses to answer questions that are "outside the classes scope" so I apologize if it's a stupid question haha

### #7

## Re: Help with displaying frequencies

Posted 07 November 2017 - 12:21 AM

Have you used structs or vectors before ?

### #8

## Re: Help with displaying frequencies

Posted 07 November 2017 - 12:36 AM

I have not, I'm reading about it now, and what you gave me is starting to make more sense.

### #9

## Re: Help with displaying frequencies

Posted 07 November 2017 - 12:53 AM

Well,

You may not be able to use it in this assignment if you haven't covered it yet I would check if you are allowed to use structs and std::vector first.

You may not be able to use it in this assignment if you haven't covered it yet I would check if you are allowed to use structs and std::vector first.

### #10

## Re: Help with displaying frequencies

Posted 07 November 2017 - 06:26 AM

Alternatively, in your other thread, you are already sorting the inputs. After you sort the inputs, then you can simply count the number of times elements adjacent to each other are equal.

Page 1 of 1