-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path25ex1.c
93 lines (73 loc) · 1.73 KB
/
25ex1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include <ctype.h>
int main()
{
int i;
int ctr = 0;
char ans;
//Declaring our array of 9 characters and then initializing them
char * movies[9] = {"Amour",
"Argo",
"Beasts of the Southern Wild",
"Django Unchained",
"Les Miserables",
"Life of Pi",
"Lincoln",
"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");
for (i=0; i < ctr; i++)
{
printf("%s rated a %d!\n", movies[i], movieratings[i]);
}
return(0);
}