4 Replies - 435 Views - Last Post: 16 September 2011 - 09:53 AM Rate Topic: -----

#1 lewieroo0  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-September 11

How do i display the current array after finding an array?

Posted 16 September 2011 - 12:16 AM

I'm in a bit of a pickle with this code i'm doing. Basically i'm making a code which stores up to 50 arrays worth of movie data (title, year released, runtime, producer, etc) which I'm making it do 4 particular functions

1. Add a movie
2. Find a movie
3. delete a movie
4. get and calculate the ratings of the current movie

Below is the code at the moment. I think the search function is working, however my question is, what's the code i need to display the current array in which i searched for?





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SIT102_Assignment1
{
    class Program
    {
        
        static void Main(string[] args)
        {
            // Declare and initialise constants
            const int MIN_YEAR = 1900;
            const int MAX_YEAR = 2011;

            // RATING constants
            const int MIN_RATING = 0;
            const int MAX_RATING = 5;

            const float ACTING_PERCENTAGE = 0.25F;
            const float MUSIC_PERCENTAGE = 0.15F;
            const float CINEMATOGRAPHY_PERCENTAGE = 0.20F;
            const float PLOT_PERCENTAGE = 0.30F;
            const float DURATION_PERCENTAGE = 0.10F;

            // Declare and initialise variables

            const int MAX_MOVIES = 50;

            // Movie variables

            string[] movie_title;
            movie_title = new string[MAX_MOVIES];

            int[] year_released;
            year_released = new int[MAX_MOVIES];

            string[] publisher;
            publisher = new string[MAX_MOVIES];

            float[] length;
            length = new float[MAX_MOVIES];


            float[] overall_rating;
            overall_rating = new float[MAX_MOVIES];

            int current_movie = -1;
            int number_of_movies_entered = 0;

            // General variables
            string[] movie_no;
            movie_no = new string[MAX_MOVIES];

            string vTemp = "";
            bool parseAttempt = false;
            string response = "";
            bool movie_data_entered = false;
            bool ratings_entered = false;

            // Rating variables
            int[] acting_rating;
            acting_rating = new int[MAX_MOVIES];

            int[] music_rating;
            music_rating = new int[MAX_MOVIES];

            int[] cinematography_rating;
            cinematography_rating = new int[MAX_MOVIES];


            int[] plot_rating;
            plot_rating = new int[MAX_MOVIES];

            int[] duration_rating;
            duration_rating = new int[MAX_MOVIES];


            // Loop until the user enter 'x'
            while (response != "x")
            {
                // Display the menu

                Console.WriteLine("-------------------------------------------");
                Console.WriteLine("Add a movie (a)");
                Console.WriteLine("Find a movie (f)");
                Console.WriteLine("Display current movie (m)");
                Console.WriteLine("Delete current movie (d)");
                Console.WriteLine("Get, Calculate and display rating for current movie (c)");
                Console.WriteLine("Exit (x)");
                Console.WriteLine("-------------------------------------------\n");
                Console.Write("Select a function: >");
                response = (Console.ReadLine());
               

                // Force the input to lower case
                response = response.ToLower();


                // Switch the response
                switch (response)
                {

                    case "a":

                        //error checking
                        if (number_of_movies_entered >= MAX_MOVIES)
                        {
                            Console.WriteLine("Maximum Amount Of Movie Entires Entered!");
                            break;
                        }

                        current_movie = number_of_movies_entered;

                        if (current_movie == MAX_MOVIES)
                        {
                            Console.WriteLine("Unable to use the next movie entry, find another!");
                            current_movie = current_movie - 1;
                            break;
                        }
                        

                        // Get movie data from the user
                        Console.WriteLine("Enter the following movie data");
                        Console.Write("  Movie Title: > ");
                        movie_title[current_movie] = Console.ReadLine();

                        parseAttempt = false;
                        while (parseAttempt == false)
                        {
                            Console.Write("  Year released > ");
                            vTemp = Console.ReadLine();
                            parseAttempt = int.TryParse(vTemp, out year_released[current_movie]);
                            // Check if data entered is a valid integer
                            if (parseAttempt == false)
                            {
                                Console.WriteLine("Error: year released must be a valid number between {0} and {1}.", MIN_YEAR, MAX_YEAR);
                            }
                            else
                                // Check data is within constraints
                                if (year_released[current_movie] < MIN_YEAR || year_released[current_movie] > MAX_YEAR)
                                {
                                    Console.WriteLine("Error: year released must be between {0} and {1}.", MIN_YEAR, MAX_YEAR);
                                    parseAttempt = false;
                                }
                        }

                        Console.Write("  Publisher > ");
                        publisher[current_movie] = Console.ReadLine();

                        parseAttempt = false;
                        while (parseAttempt == false)
                        {
                            Console.Write("  Length (hrs) > ");
                            vTemp = Console.ReadLine();
                            parseAttempt = float.TryParse(vTemp, out length[current_movie]);
                            // Check if data entered is a valid float
                            if (parseAttempt == false)
                            {
                                Console.WriteLine("Error: length must be a valid number  greater than 0.");
                            }
                            else
                                // Check data is within constraints
                                if (length[current_movie] <= 0)
                                {
                                    Console.WriteLine("Error: length must be a valid number  greater than 0.");
                                    parseAttempt = false;
                                }
                        }

                        //Set the flag so we know we have entered the movie data
                        movie_data_entered = true;


                        number_of_movies_entered = number_of_movies_entered + 1;
                        break;

                    case "f":

                         

                        string find_data = "";
                        int item = 0;
                        Console.WriteLine("Enter Movie Title to find:");
                        find_data = Console.ReadLine();
                        for (item = 0; item < number_of_movies_entered; item++)
                        {
                            if (movie_title[item] == find_data)
                            {
                                current_movie = item;
                                break;
                            }                       
                        }
                        break;
                    
                      


                    case "m":

                        break;
                        
                    case "d":





                        break;

                    case "c":
                        
                        // Get the rating data for the movie from the user
                        Console.WriteLine("Rate the following out of {0}", MAX_RATING);

                        // Acting rating
                        parseAttempt = false;
                        while (parseAttempt == false)
                        {
                            Console.Write("  Acting > ");
                            vTemp = Console.ReadLine();
                            parseAttempt = int.TryParse(vTemp, out acting_rating[current_movie]);
                            // Check if data entered is a valid integer
                            if (parseAttempt == false)
                            {
                                Console.WriteLine("Error: acting rating must be a valid number between {0} and {1}.", MIN_RATING, MAX_RATING);
                            }
                            else
                                // Check data is within constraints
                                if (acting_rating[current_movie] < MIN_RATING || acting_rating[current_movie] > MAX_RATING)
                                {
                                    Console.WriteLine("Error: acting rating must be a valid number between {0} and {1}.", MIN_RATING, MAX_RATING);
                                    parseAttempt = false;
                                }
                        }

                        // Music rating
                        parseAttempt = false;
                        while (parseAttempt == false)
                        {
                            Console.Write("  Music > ");
                            vTemp = Console.ReadLine();
                            parseAttempt = int.TryParse(vTemp, out music_rating[current_movie]);
                            // Check if data entered is a valid integer
                            if (parseAttempt == false)
                            {
                                Console.WriteLine("Error: music rating must be a valid number between {0} and {1}.", MIN_RATING, MAX_RATING);
                            }
                            else
                                // Check data is within constraints
                                if (music_rating[current_movie] < MIN_RATING || music_rating[current_movie] > MAX_RATING)
                                {
                                    Console.WriteLine("Error: music rating must be a valid number between {0} and {1}.", MIN_RATING, MAX_RATING);
                                    parseAttempt = false;
                                }
                        }

                        // Cinematography rating
                        parseAttempt = false;
                        while (parseAttempt == false)
                        {
                            Console.Write("  Cinematography > ");
                            vTemp = Console.ReadLine();
                            parseAttempt = int.TryParse(vTemp, out cinematography_rating[current_movie]);
                            // Check if data entered is a valid integer
                            if (parseAttempt == false)
                            {
                                Console.WriteLine("Error: cinematography rating must be a valid number between {0} and {1}.", MIN_RATING, MAX_RATING);
                            }
                            else
                                // Check data is within constraints
                                if (cinematography_rating[current_movie] < MIN_RATING || cinematography_rating[current_movie] > MAX_RATING)
                                {
                                    Console.WriteLine("Error: cinematography rating must be a valid number between {0} and {1}.", MIN_RATING, MAX_RATING);
                                    parseAttempt = false;
                                }
                        }

                        // Plot rating
                        parseAttempt = false;
                        while (parseAttempt == false)
                        {
                            Console.Write("  Plot > ");
                            vTemp = Console.ReadLine();
                            parseAttempt = int.TryParse(vTemp, out plot_rating[current_movie]);
                            // Check if data entered is a valid integer
                            if (parseAttempt == false)
                            {
                                Console.WriteLine("Error: plot rating must be a valid number between {0} and {1}.", MIN_RATING, MAX_RATING);
                            }
                            else
                                // Check data is within constraints
                                if (plot_rating[current_movie] < MIN_RATING || plot_rating[current_movie] > MAX_RATING)
                                {
                                    Console.WriteLine("Error: plot rating must be a valid number between {0} and {1}.", MIN_RATING, MAX_RATING);
                                    parseAttempt = false;
                                }
                        }

                        // Duration rating
                        parseAttempt = false;
                        while (parseAttempt == false)
                        {
                            Console.Write("  Duration > ");
                            vTemp = Console.ReadLine();
                            parseAttempt = int.TryParse(vTemp, out duration_rating[current_movie]);
                            // Check if data entered is a valid integer
                            if (parseAttempt == false)
                            {
                                Console.WriteLine("Error: duration rating must be a valid number between {0} and {1}.", MIN_RATING, MAX_RATING);
                            }
                            else
                                // Check data is within constraints
                                if (duration_rating[current_movie] < MIN_RATING || duration_rating[current_movie] > MAX_RATING)
                                {
                                    Console.WriteLine("Error: duration rating must be a valid number between {0} and {1}.", MIN_RATING, MAX_RATING);
                                    parseAttempt = false;
                                }
                        }
                        ratings_entered = true;

                        // Check if we have data to calculate and display
                        if (movie_data_entered != true || ratings_entered != true)
                        {
                            Console.WriteLine("You must enter the movie data and rate the movie before you can procees this option.");
                            break;
                        }
                        // Calculate the overall rating
                        overall_rating[current_movie] = (acting_rating[current_movie] * ACTING_PERCENTAGE) + (music_rating[current_movie] * MUSIC_PERCENTAGE) + (cinematography_rating[current_movie] * CINEMATOGRAPHY_PERCENTAGE) + (plot_rating[current_movie] * PLOT_PERCENTAGE) + (duration_rating[current_movie] * DURATION_PERCENTAGE);
                        overall_rating[current_movie] = overall_rating[current_movie] * 2;
                        // Round the value to o decimal places
                        overall_rating[current_movie] = (float)Math.Round(overall_rating[current_movie], 0);

                        // Output the movie data
                        Console.WriteLine();
                        Console.WriteLine("Movie Information");
                        Console.WriteLine("Movie Title : \t\t{0}", movie_title[current_movie]);
                        Console.WriteLine("Year released : \t{0}", year_released[current_movie]);
                        Console.WriteLine("Publisher  : \t\t{0}", publisher[current_movie]);
                        Console.WriteLine("Length (hrs) : \t\t{0}", length[current_movie]);
                        Console.WriteLine("Ratings");
                        Console.WriteLine("Acting : \t\t{0}", acting_rating[current_movie]);
                        Console.WriteLine("Music : \t\t{0}", music_rating[current_movie]);
                        Console.WriteLine("Cinematography :\t{0}", cinematography_rating[current_movie]);
                        Console.WriteLine("Plot : \t\t\t{0}", plot_rating[current_movie]);
                        Console.WriteLine("Duration : \t\t{0}", duration_rating[current_movie]);
                        Console.WriteLine();
                        Console.Write("Overall rating is {0} / 10 : ", overall_rating[current_movie]);
                        // Write the star rating 
                        for (int star = 0; star < (int)overall_rating[current_movie]; star++)
                        {
                            Console.Write("*");
                        }
                        Console.WriteLine();
                        break;

                    default:
                        Console.WriteLine("Invalid option.");
                        break;
                    } //End switch
                } // End Menu while
            }
        }
    }

This post has been edited by CodingSup3rnatur@l-360: 16 September 2011 - 12:54 AM
Reason for edit:: Please use code tags [code]CODE HERE[/code]


Is This A Good Question/Topic? 0
  • +

Replies To: How do i display the current array after finding an array?

#2 ragingben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 170
  • View blog
  • Posts: 637
  • Joined: 07-October 08

Re: How do i display the current array after finding an array?

Posted 16 September 2011 - 01:39 AM

Hi, is there any reason you haven't set up a class for Movie? Really you should be using a class that represents a Movie objct that contains all the information for the movie (name, duration, year, rating etc). This would make everything less confusing because you could just store a list of these movies and then search for them very easily.

For your search function you are finding the index of the movie, so you can use this to access the elements in the arrays. Try adding the following line after line 193 as an example
Console.WriteLine("Title: {0}", movie_title[current_movie]);


Was This Post Helpful? 3
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: How do i display the current array after finding an array?

Posted 16 September 2011 - 05:14 AM

As ragingben has stated, you should definitely look into using a class called Movie that will store all of the pieces of information about a movie. This would allow you to have 1 collection of "Movies", instead of 50 different arrays for each piece of data.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5432
  • View blog
  • Posts: 11,643
  • Joined: 02-June 10

Re: How do i display the current array after finding an array?

Posted 16 September 2011 - 07:22 AM

lewieroo0 Is this for a school assignment? If you haven't learned how to make classes yet then the very good advice that you need them won't really apply. If you course has only included arrays then you need to use arrays. So is this for school?
Was This Post Helpful? 0
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2239
  • View blog
  • Posts: 9,409
  • Joined: 29-May 08

Re: How do i display the current array after finding an array?

Posted 16 September 2011 - 09:53 AM

A tutorial that demonstrates the difference. (VB.net code)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1