B modify the movie rating program so that a user gets

This preview shows page 26 - 31 out of 40 pages.

b. Modify the movie-rating program so that a user gets three tries to enter a valid rating. After three incorrect entries, the program issues an appropriate message and continues with a new user.
Programming Logic and Design, 7eSolutions 5-27Pseudocode:startDeclarationsnum numOfStarsnum count = 0num total = 0num attemptsnum avgnum LIMIT = 3string PROMPT = “Enter the star rating or a negative number to quit >> ”housekeeping()while numOfStars >= 0 AND attempts < LIMITdetailLoop()
c. Modify the movie-rating program so that the user is prompted continuously for a movie title untilZZZZZis entered. Then, for each movie, continuously accept star-rating values until a negative number is entered. Display the average rating for each movie.
Programming Logic and Design, 7eSolutions 5-29Pseudocode:startDeclarations
Programming Logic and Design, 7eSolutions 5-30string movieTitlenum numOfStarsnum count = 0num total = 0num avgstring STAR_PROMPT = “Enter a star rating or a negative number for a new movie >> ”string MOVIE_PROMPT = “Enter a movie title or ZZZZZ to quit >> ”housekeeping()while movieTitle <> “ZZZZZ”detailLoop()endwhilefinishUp()stophousekeeping()output MOVIE_PROMPTinput movieTitlereturndetailLoop()output STAR_PROMPTinput numOfStarswhile numOfStars >= 0getStarRating()endwhilecalcAverage()output MOVIE_PROMPTinput movieTitlereturngetStarRating()while numOfStars > 4 OR numOfStars < 0output “Please re-enter a value from 0 to 4 >> ”input numOfStarsendwhilecount = count + 1total = total + numOfStarsoutput STAR_PROMPTinput numOfStarsreturncalcAverage()avg = total / countoutput “The average star rating for ”, movieTitle, “ is: ”, avgreturnfinishUp()output “End of program”return

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture