Hi I need to figure out how to make a histogram for a set of data (scores).
I need it to display something like
A: ***
B: **
C: ******
D: *
F: ****
Here is my function for adding in the scores

int addGrades(int grades[], int num_grades)
  int i = 0;
  int count;
  printf("\nEnter grades, with 10 being the maximum number of grades:\n");  
  for(i = 0; i < num_grades; i++)
    { /* start of for loop */
      printf("%2d> ", i+1);
      scanf("%d", &grades[i]);
    } /* end of for loop */
  return num_grades;
} /* end of addGrades */

and here is my function to view the array

void displayGrades(int grades[], int num_grades)
  int i = 0;
  printf("Here are the grades collected: \n");
  for(i = 0; i < num_grades; i++)
    { /* start of for loop */
      printf("%4d", grades[i]);
    } /* end of for loop */
  printf("\n"); /* prints a blank line */
} /* end of displayGrades */

Recommended Answers

All 3 Replies

Imo, it's best to make a 2D array (static) for your data. That is your histograms, which you will fill in, before you print it.

The code is a bit longer, but I like it because you can view one row of the array, as it's being made up, and ensure it's accurate.

In your case, A would be on the zero'th row, and F would be on the highest row.

What is your question or problem?

My question is I have no idea how to start of the function for the histogram.

You have to first set up your design for the histogram.

What is the range of the historgram (lowest and highest).

Just four students will be shown in it?

What will each star represent, as a number or letter? What grade or score gets what number of stars?

char gr[50][4], might be OK, depending on your answers to the above questions.

Be a part of the DaniWeb community

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