Inline Code Example Here

I have been trying to solve this but i just can't get it right... can someone help me pls?

Using array to summarize survey results
40 Students were asked to rate the quality of the food in the student cafeteria on
a scale of 1 to 10 (1 means bad and 10 means excellent). Place the 40
responses in an integer array and summarize the results of the survey.
• Summarize the number of responses of each type (1 through 10)
• The array responses is a 40-element array of students’ responses.
• The array frequency is a 11-element array to count the number of
occurrences of each response.
responses array elements are = {1, 2, 6, 4, 8, 5, 9, 7, 8, 10, 1, 6, 3, 8, 6, 10,
3, 8, 2, 7, 6, 5, 7, 6, 8, 6, 7, 5, 6, 6, 5, 6, 7, 5, 6, 4, 8, 6, 8, 10}
Hint: initialize frequency counter to zero. Initialize responses array elements

**Sample Output**

Scale    Frequency
1          2
2          2
3          2
4          2
5          5
6         11
7         5
8         7
9         1
10        3

What code do you have so far? You're supposed to give us what you have so far, and we'll be happy to help but, but we're not allowed to be doing your homework for you.

This code might help you get started. But try writing the code yourself.

#include <iostream>

using namespace std;

int main()
{

int responses[] = {1, 2, 6, 4, 8, 5, 9, 7, 8, 10, 1, 6, 3, 8, 6, 10,3, 8, 2, 7, 6, 5, 7, 6, 8, 6, 7, 5, 6, 6, 5, 6, 7, 5, 6, 4, 8, 6, 8, 10};

int freq[11]={0};

int i,j;
i=j=0;
cout<<"Scale"<<"\t"<<"Freq"<<endl;
for(i=1;i<11;i++)
{

  for(j=0;j<40;j++)
  {
    if(i==responses[j])
     {
        freq[i]++;
     } 
  }

   cout<<i<<"\t"<<freq[i]<<endl;
}


return 0;

}

To be sincere I don't have any code yet because I couldn't understand it... You can explain it o me for understanding than doing it. I just want to learn. I have problems with array

Thanks for the solution... Any printf solution?

# include<stdio.h>
#define frequencySize 11
#define responses 40

int main()
{ 
    int survey, scale; 
    int response[responses]={1, 2, 6, 4, 8, 5, 9, 7, 8, 10, 1, 6, 3, 8, 6, 10, 3, 8, 2, 7, 6, 5, 7, 6, 8, 6, 7, 5, 6, 6, 5, 6, 7, 5, 6, 4, 8, 6, 8, 10}; 
    int frequency[frequencySize] = {0};

    for(survey = 1; survey < responses; survey++) 
        ++frequency[response[surv]];
        printf("%s%17s\n","Scale","Frequency");
    {
        for(scale = 1; scale < frequencySize; scale++)
        printf("%d%17d\n",scale, frequency[scale]); 
    }

    return 0;
}

Here is my solution but its not running on the compiler. What am I doing wrong?

line 12 it's ++frequency[response[survey]]; not ++frequency[response[surv]];.
Use what Software guy gave you, basically, in there is your whole assignment. After that just print in parallel the arrays: the index and the element.

I corrected it but it didn't run yet. I can't use software guy solution because i don't use Cout for printing. So I want to do it myself. Pls help me check for my mistakes

What is the code you have now?

#include<stdio.h>
#define frequencySize 11
#define responses 40
int main()
{
  int survey, scale;
  int response[responses]={1, 2, 6, 4, 8, 5, 9, 7, 8, 10, 1, 6, 3, 8, 6, 10, 3, 8, 2, 7, 6, 5, 7, 6, 8, 6, 7, 5, 6, 6, 5, 6, 7, 5, 6, 4, 8, 6, 8, 10};
  int frequency[frequencySize] = {0};
  for(survey = 0; survey < responses; survey++)
  ++frequency[response[survey]];
  printf("%s%17s\n","Scale","Frequency");
  {
   for(scale = 1; scale < frequencySize; scale++)
    printf("%d%17d\n",scale, frequency[scale]);
  }
  return 0;
}

Working version of your code.

Thank you for your helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.