1. ## Problem with calculating

Hi all i make program for rating movies with matrix, I use 5 movies but calculating marks in not good it's give me some other numbers than real
Code:
```#include <stdio.h>int main()
{
int a,i,j,g=0;
float s=1;
float max=0;
for(i=0; i<5; i++)
{
for(j=0; j<5; j++)
{
scanf("%d",&a[i][j]);
}
}
i=0;
for(j=0; j<5; j++)
{
s+=a[i][j]/5;
if(s>max)
{
max=s;
g=j;
}
printf("Movie %d mark %.2f",j,s);
}
printf("Biggest mark have movie number %d, mark: %.2f",g,max);
}``` 2. > s+=a[i][j]/5;
1. i is fixed at 0, so why did you input all those extra numbers?

2. a is an array of integers, so divide by 5 will truncate. 8 for example, will simply be 1 rather than 1.6. 3. I change array in float but again is not giving me real result 4. Originally Posted by John5 Hi all i make program for rating movies with matrix
How?

We know that you are working with five movies, and ask the user 5×5 numbers.

What we do not know, is how this matrix should be interpreted. Does each row correspond to a movie, and column to a specific critic? Or something else? Until we know what the matrix represents, and how and what information you wish to extract from it, helping you is pretty much just guesswork. Please, help us help you. 5. Every row is marks just for one movie, i enter 5 marks for every movie 6. Do you need the separate marks for each movie, or just the average and the maximum? 7. I just need average mark for every movie and biggest average mark and what movie has biggest average mark. 8. Are the movie ratings given in a specific format, on can you require any input format you want? 9. You can only enter marks from 1-10 in every row you have 5 marks and there is 5 movies 10. In that case, why don't you use a loop over each movie, and an inner loop that remembers the number of scores, the sum of those scores, and the maximum score given, for that movie?

If the scores for the same movie are separated by spaces, movies are separated by commas, and the input ends with a period, you might use something like the following:
Code:
```#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

#define MAX_MOVIES  50

int main(void)
{
int movie_scores[MAX_MOVIES];
int movie_maxscore[MAX_MOVIES];
int movie_sumscore[MAX_MOVIES];
int movies = 0;

fprintf(stderr, "Please supply movie scores [1 - 10] separated by spaces.\n");
fprintf(stderr, "Separate movies with a comma ','.\n");
fprintf(stderr, "End the input with a period '.'.\n");
fflush(stderr);

while (movies < MAX_MOVIES) {
int  scores = 0;    /* No scores given for this movie */
int  sum    = 0;    /* Sum of scores given to this movie */
int  max    = 0;    /* Largest score given to this movie */
int  s;             /* Current score */
int  c;             /* Temporary character */

while (scanf("%d", &s) == 1)
if (s >= 1 && s <= 10) {
if (max < s)
max = s;
sum += s;
scores++;
} else {
fprintf(stderr, "Error: Score %d is invalid.\n", s);
return EXIT_FAILURE;
}

if (scores > 0) {
fprintf(stderr, "Movie %d: %d scores given, highest %d, average %.2f\n",
movies + 1, scores, max, (double)sum / (double)scores);
fflush(stderr);

/* Save into the three movie arrays. */
movie_scores[movies] = scores;
movie_maxscore[movies] = max;
movie_sumscore[movies] = sum;
movies++;
}

do {
c = getc(stdin);
} while (c != EOF && isspace(c));

/* No more movies? */
if (c == '.' || c == EOF)
break;

/* Next movie? */
if (c == ',')
continue;

fprintf(stderr, "Error: Invalid character '%c' in input.\n", c);
return EXIT_FAILURE;
}

if (movies < 1) {
fprintf(stderr, "No movies scored.\n");
return EXIT_FAILURE;
}

fprintf(stderr, "Scored %d movies.\n", movies);
fflush(stderr);

return EXIT_SUCCESS;
}```
For example, if you input 4 6 7, 2 3 1 4 1 1, 7 8 4 3, 6. it will output
Please supply movie scores [1 - 10] separated by spaces.
Separate movies with a comma ','.
End the input with a period '.'.
Movie 1: 3 scores given, highest 7, average 5.67
Movie 2: 6 scores given, highest 4, average 2.00
Movie 3: 4 scores given, highest 8, average 5.50
Movie 4: 1 scores given, highest 6, average 6.00
Scored 4 movies.
For movie i, 0 <= i and i < movies,
the number of scores given is movie_scores[i]
the highest score is movie_maxscore[i]
the average score is (double)movie_sumscore[i] / (double)movie_scores[i]
so you can easily add whatever movie comparisons you want. 11. I need to make this program with matrix not just with loops. 12. Getting information out from you is like pulling teeth. You could have stated the requirements in your initial post, and saved three days of waffling.

If you had added the point of the exercise -- that is, what features of the C language this is intended to help you get familiar with --, that would have made the question interesting. 13. I don't know what anything to explain, from code above you can see that i work with matrix, not just with loops. 14. Originally Posted by John5 I need to make this program with matrix not just with loops.
Why?

Because it's one of those pointless exercises which is basically akin to teaching you magic tricks, as opposed to teaching you how to program.

Any sane program would use loops to implement a generic matrix multiply.

OK, 3x3 is about the limit you would want to go to if you were seeking max speed and could be bothered to write out all the steps by hand.

But at 5x5, it's looking kinda silly and pointless. 15. I need this program for school i know that just with loops is more practial but tell that to old school teaching program. Popular pages Recent additions 