Question: C# Help: This code allows user to enter a movie title and enters ratings between 0-4 and if a negative number is entered the code

C# Help:

This code allows user to enter a movie title and enters ratings between 0-4 and if a negative number is entered the code is exited and average of rating is calculated. Edit the following code to only allow numbers 0-4 and gets 3 times to retry and if not corrected code will exit and average will still be displayed.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace ConsoleApp3 { public class MovieRating { public static void Main(string[] args) { Console.Write("Enter movie title: "); string title = Console.ReadLine(); double total = 0, rating; int count = 0; while (true) { Console.Write("Enter movie rating[0-4](negative to exit): "); rating = Convert.ToDouble(Console.ReadLine()); if (rating < 0) break; total += rating; count++; }

Console.WriteLine("Average rating of " + title + " is " + (total / count)); Console.ReadLine(); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!