Problem 1. Suppose you have to design software for the Oscar Jury members where they can ate the nominated movies on a scale of 1-10. Here is the movie list • Nayak: The Hero • The Cloud-Capped Star • The Music Room ● Pather Panchali Charulata Subarnarekha Days and Nights in the Forest • • The Unnamed The program will ask five judges to rate movies one by one. After completing the rating from all ive judges, the output window will show the movie name and its rating in a. ascending order of rating if your ID is even. b. descending order of rating if your ID is odd. Note: Use of Pointer is mandatory.
Use the descending order. And kindly give a description below after completing the code in C.
Step by step
Solved in 2 steps
Please give the correction from this code, where I made the mistakes. The extra two output shown here. How to remove that?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// movie structure
struct movie {
char movieName[1025];
int rating;
};
int main(void) {
// movie structure variable
struct movie list[10];
// movie structure pointer variable
struct movie *ptr = list;
int ID;
// assign std to ptr
char buff;
for (int i = 0; i < 8; i++) {
printf("Enter number %d movie name: ",i+1);
//scanf("%s",&ptr->movieName);
gets(ptr->movieName);
printf("Enter rating: ");
scanf("%d", &ptr->rating);
buff = getchar();
// update pointer to point at next element
ptr++;
}
// reset pointer back to the starting
ptr = list;
printf("Enter your ID: ");
scanf("%d",&ID);
struct movie temp;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < (9 - i); j++)
{
if (list[j].rating < list[j + 1].rating)
{
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
}
if(ID%2){
for (int i = 0; i < 10; i++)
printf("%s %d\n", list[i].movieName,list[i].rating);
}
else {
for (int i = 9; i >=0; i--)
printf("%s %d\n", list[i].movieName,list[i].rating);
}
return 0;
}