9 Replies - 351 Views - Last Post: 07 November 2017 - 06:26 AM Rate Topic: -----

#1 hh38985  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 06-November 17

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.

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;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Help with displaying frequencies

#2 albert003  Icon User is offline

  • D.I.C Regular

Reputation: 14
  • View blog
  • Posts: 370
  • Joined: 15-December 14

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.
Was This Post Helpful? 0
  • +
  • -

#3 hh38985  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 06-November 17

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 :(
Was This Post Helpful? 0
  • +
  • -

#4 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 590
  • View blog
  • Posts: 2,484
  • Joined: 13-June 14

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?
Was This Post Helpful? 0
  • +
  • -

#5 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 1377
  • View blog
  • Posts: 4,318
  • Joined: 20-March 10

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

Posted Image

Where MXr is the total of the number added together and N is the amount itself
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

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

Was This Post Helpful? 1
  • +
  • -

#6 hh38985  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 06-November 17

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
Was This Post Helpful? 0
  • +
  • -

#7 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 1377
  • View blog
  • Posts: 4,318
  • Joined: 20-March 10

Re: Help with displaying frequencies

Posted 07 November 2017 - 12:21 AM

Have you used structs or vectors before ?
Was This Post Helpful? 0
  • +
  • -

#8 hh38985  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 06-November 17

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.
Was This Post Helpful? 0
  • +
  • -

#9 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 1377
  • View blog
  • Posts: 4,318
  • Joined: 20-March 10

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.
Was This Post Helpful? 0
  • +
  • -

#10 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5895
  • View blog
  • Posts: 20,126
  • Joined: 05-May 12

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1