C Programming Absolute Beginner's Guide (3rd Edition)

(Romina) #1

"Silver Linings Playbook",
"Zero Dark Thirty"};
int movieratings[9]; // A corresponding array of 9 integers
// for movie ratings


char * tempmovie = "This will be used to sort rated movies";
int outer, inner, didSwap, temprating; // for the sort loop


printf("\n\n Oscar Season 2012 is here! \n\n");
printf("Time to rate this year's best picture nominees:");


for (i=0; i< 9; i++)
{
printf("\nDid you see %s? (Y/N): ", movies[i]);
scanf(" %c", &ans);
if ((toupper(ans)) == 'Y')
{
printf("\nWhat was your rating on a scale ");
printf("of 1-10: ");
scanf(" %d", &movieratings[i]);
ctr++; // This will be used to print only movies
// you've seen
continue;
}
else
{
movieratings[i] = -1;
}
}


// Now sort the movies by rating (the unseen will go
// to the bottom)


for (outer = 0; outer < 8; outer++)
{
didSwap = 0;
for (inner = outer; inner < 9; inner++)
{
if (movieratings[inner] > movieratings[outer])
{
tempmovie = movies[inner];
temprating = movieratings[inner];
movies[inner] = movies[outer];
movieratings[inner] = movieratings[outer];
movies[outer] = tempmovie;
movieratings[outer] = temprating;
didSwap = 1;
}
}
if (didSwap == 0)
{
break;
}
}


// Now to print the movies you saw in order
printf("\n\n Your Movie Ratings for the 2012 Oscar ");
printf("Contenders
\n");

Free download pdf