View Single Post
pichlo's Avatar
Posts: 6,445 | Thanked: 20,981 times | Joined on Sep 2012 @ UK
#8
Your movie names get concatenated. Why do you think this is? What do you use to contain the names and how do you initialize it? (Hinr: you use a single string and you get the name into it by appending one character at a time.) What happens when you enter a new name?

Regarding your average ratings, I find I do not understand how you calculate them. In your own example, you rated American Pie as 4 and Thor as 5. You gave each of them just one rating, so I would expect the averages to be 4 and 5, respectively. Why are they 0.2? Maybe it's as intended, but it's not what I would expect, which is why I said I'd leave it to your tutor.

Humble is right, your code layout is a bit awkward. There is a lot of repetition. In general, if you find yourself writing the same code twice, you are doing something wrong. Even as few as two copies call for separating the common code into a function.

Maybe I'm wrong. I do not know what your assignemt says exactly, but the way I would have approached is something like this (in pseudocode)...
Code:
loop
   read_movie_name

   loop
      read_rating
      ask "rate again?"
      if (answer_was_no)
         break loop
   end loop

   calculate_averages

   ask "another movie?"
   if (answer_was_no)
      break loop
end loop
To calculate averages, I would divide the sum of all ratings by their number.
 

The Following User Says Thank You to pichlo For This Useful Post: