C Program - Cafeteria Rating
Submitted by davidwachira on Tuesday, August 6, 2013 - 19:58.
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
- #include<stdio.h> /* Standard C Library*/
- #define students 40 /* Constant students*/
- #define max_rating 10 /* Constant max_rating*/
- int cafeteria_rating_array[students][1]; /* Declaration of 2D-Array */
- int students_counter, total_rating; /* Declaration of 2 variables called students_counter and total_rating*/
- int frequency_array[max_rating][2]; /* Declaration of 2D-Array*/
- int frequency_counter, frequency_count; /* Declaration of 2 variables called frequency_counter and frequency_count*/
- int i,j; /* Declaration of 2 variables to be used in as part of the counter*/
- int main(void)/* The main method*/
- {
- 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");
- 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");
- for(students_counter=0;students_counter<students;students_counter++) /* Loop to ensure that the input is within range*/
- {
- do
- 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");}
- }
- while (cafeteria_rating_array[students_counter][1] < 1 || cafeteria_rating_array[students_counter][1] > max_rating );
- total_rating+=cafeteria_rating_array[students_counter][1];
- }
- for (students_counter=0;students_counter<students;students_counter++) /* Output of the data already in the cafeteria_rating_array*/
- { printf( "Student no. %d rated the cafeteria food %d/10\n", students_counter+1, cafeteria_rating_array[students_counter][ 1 ] );
- }
- for (frequency_counter=0;frequency_counter<max_rating;frequency_counter++)
- { frequency_array[frequency_counter][0]=frequency_counter+1;
- frequency_count=0;
- for (students_counter=0;students_counter<students;students_counter++)
- {
- if (cafeteria_rating_array[students_counter][ 1 ]==frequency_counter+1)
- {
- frequency_count=frequency_count+1;
- }
- }
- frequency_array[frequency_counter][1]=frequency_count;
- }
- printf( "\nThe rating average is %.1f/10\n", (double)total_rating/students); /* Getting the average rating and its display*/
- for ( i = 0; i <max_rating; i++ ) /* Output of poll results*/
- { for ( j = 0; j < 2; j++ )
- }
- return 0;/* An indication that the program has run successfully */
- }
- <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
- 463 views