The problem is---
Must use arrays - Ask the user for ratings for a professor in a loop. The ratings can go from 0 to 100. Allow the user to keep entering ratings, until they type in -1. Store these ratings in an appropriate array.
Once the user is done entering values, print how how many of each rating a professor has. Show the highest ratings first, and do not show ratings that weren't given. Also print out the total number of ratings and the average.
Example:
Enter rating (-1 to quit): 90
Enter rating (-1 to quit): 89
Enter rating (-1 to quit): 88
Enter rating (-1 to quit): -100
Error..ratings must be between 0 and 100.
Enter rating (-1 to quit): 101
Error..ratings must be between 0 and 100.
Enter rating (-1 to quit): 88
Enter rating (-1 to quit): -1
There were 4 ratings entered
1 rating(s) of 90
1 rating(s) of 89
2 rating(s) of 88
The average of the ratings were: 88.75
----------
My code is
------------
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int rating[100]; // size of 100
int freq[100]; // size of 100
int t; // total number of rating
int size;
int i = 0, j = 0; // two counters
int count = 0;
const int Quit = -1;
double average;
double total;
/* Input elements in rating */
printf("Enter rating (-1 to quit): ", i + 1);
scanf_s("%d", &rating[i]);
for (i = 0; i<size; i++)
{
scanf("%d", &rating[i]);
/* Initially initialize frequencies to -1 */
freq[i] = -1;
}
for (i = 0; i<size; i++)
{
count = 1;
for (j = i + 1; j<size; j++)
{
/* If duplicate rating is found */
if (rating[i] == rating[j])
{
count++;
/* Make sure not to count frequency of same rating again */
freq[j] = 0;
}
}
/* If frequency of current rating is not counted */
if (freq[i] != 0)
{
freq[i] = count;
}
}
/*
* Print frequency of each rating
*/
printf("\nThere were %d ratings entered\n", total amount of ratings);
for (i = 0; i<size; i++)
{
if (freq[i] != 0)
{
printf("%d rating(s) of %d \n", freq[i], rating[i]);
}
}
return 0;
}