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]

New Topic/Question
Reply



MultiQuote






|