C Program - Cafeteria Rating

Language

Fourty students were asked to rate the quality of food in the student cafeteria on a scale of 1 to 10(1 means awful and 10 means excellent) Place the 40 responses in an integer array and summarise and display the results of the poll
  1. #include<stdio.h> /* Standard C Library*/
  2. #define students 40 /* Constant students*/
  3. #define max_rating 10 /* Constant max_rating*/
  4.  
  5. int cafeteria_rating_array[students][1]; /* Declaration of 2D-Array */
  6. int students_counter, total_rating; /* Declaration of 2 variables called students_counter and total_rating*/
  7. int frequency_array[max_rating][2]; /* Declaration of 2D-Array*/
  8. int frequency_counter, frequency_count; /* Declaration of 2 variables called frequency_counter and frequency_count*/
  9. int i,j; /* Declaration of 2 variables to be used in as part of the counter*/
  10.  
  11.  
  12. int main(void)/* The main method*/
  13. {
  14. printf("/**************************************************************************\n * Mureithi David Wachira *\n * P15/2204/2011 *\n * *\n * University of Nairobi *\n * School of Computing & Informatics *\n * *\n * Date: Thursday 28th February 2013 *\n * *\n * Fourty students were asked to rate the quality *\n * of food in the student cafeteria on a scale *\n * of 1 to 10(1 means awful and 10 means excellent) *\n * Place the 40 responses in an integer array and *\n * summarise and display the results of the poll *\n * *\n *************************************************************************/\n");
  15. printf("Please rate the quality of food in the cafeteria on a scale of 1 to 10;\n1 meaning awful and 10 meaning excellent:\n\n");
  16.  
  17. for(students_counter=0;students_counter<students;students_counter++) /* Loop to ensure that the input is within range*/
  18. {
  19. do
  20. { printf("Student no. %d :\t", students_counter+1);
  21. scanf("%d", &cafeteria_rating_array[students_counter][1]);
  22. if(cafeteria_rating_array[students_counter][1] < 1 || cafeteria_rating_array[students_counter][1] > max_rating ){printf("Please enter an valid. The range is between 1 and 10\n");}
  23. }
  24. while (cafeteria_rating_array[students_counter][1] < 1 || cafeteria_rating_array[students_counter][1] > max_rating );
  25. total_rating+=cafeteria_rating_array[students_counter][1];
  26. }
  27.  
  28.  
  29. printf( "\n\n"); /* Skip 2 lines*/
  30.  
  31. for (students_counter=0;students_counter<students;students_counter++) /* Output of the data already in the cafeteria_rating_array*/
  32. { printf( "Student no. %d rated the cafeteria food %d/10\n", students_counter+1, cafeteria_rating_array[students_counter][ 1 ] );
  33. }
  34.  
  35. for (frequency_counter=0;frequency_counter<max_rating;frequency_counter++)
  36. { frequency_array[frequency_counter][0]=frequency_counter+1;
  37. frequency_count=0;
  38.  
  39. for (students_counter=0;students_counter<students;students_counter++)
  40. {
  41. if (cafeteria_rating_array[students_counter][ 1 ]==frequency_counter+1)
  42. {
  43. frequency_count=frequency_count+1;
  44. }
  45. }
  46. frequency_array[frequency_counter][1]=frequency_count;
  47.  
  48. }
  49.  
  50.  
  51.  
  52.  
  53. printf( "\nThe rating average is %.1f/10\n", (double)total_rating/students); /* Getting the average rating and its display*/
  54.  
  55. printf("\nThe poll results are:\n");/* Output on the screen for poll results*/
  56.  
  57. for ( i = 0; i <max_rating; i++ ) /* Output of poll results*/
  58. { for ( j = 0; j < 2; j++ )
  59. {printf("%5d\t", frequency_array[i][j]);}
  60. printf("\n");
  61.  
  62. }
  63.  
  64.  
  65.  
  66. return 0;/* An indication that the program has run successfully */
  67. }
  68. <c>

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment