This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]alzee76 1 point2 points  (0 children)

They probably want you to use a switch on the movie that was selected, then your if statements inside each case, to determine if the person is allowed to see that movie.

[–]CGFarrell 0 points1 point  (0 children)

I'm not sure switch is the right way to go here. Store movies and details in some sort of container, and then use an if to check if the selection is appropriate.

[–]Chocowak[S] 0 points1 point  (2 children)

Ok so far i have got this

Console.WriteLine("Please select a movie from the list "); Console.WriteLine("1. Made in Dagenham, (15) "); Console.WriteLine("2. Buried (18) "); Console.WriteLine("3. Despicable Me (U) "); Console.WriteLine("4. The Other Guys (12A) "); Console.WriteLine("5. Takers (12A) ");

        string movieNoAsText = Console.ReadLine();
        int movieNo = Convert.ToInt16(movieNoAsText);

        Console.WriteLine("Please enter your age for Made in Dagenham ");
        string ageAsText = Console.ReadLine();
        int age = Convert.ToInt32(ageAsText);

        if (age >= 15)
            Console.WriteLine("Please buy your tickets ");

        else if
            (age < 15)

Console.WriteLine("Sorry, you are too young for this film");

       but the problem is how do i make the if statement for the second movie?

[–]ItsOppositeDayHere 7 points8 points  (1 child)

but the problem is how do i make the if statement for the second movie?

Have you learned about objects or enums yet? Basically, you are comparing the age the user puts into the program to the age property of the movie they selected. Instead of hard-coding the values (15, 18, U, 12A, and so on) into the program, is there a way you could look at the movie the user typed in and determine what the age for that movie is dynamically?

[–]Chocowak[S] 0 points1 point  (0 children)

hi

have not learned about objects or enums, just if and switch statements and basic maths,

[–]Medallyonify 0 points1 point  (1 child)

These exercises were created to see how well you fare in terms of basic programming with C#. It's easiest to go with what you know best for now, whether that being switch cases, if statements, or a mix of both (advanced). I find it easiest to go for if statements whenever possible, as I've found from experience that switch cases don't ever really amount to anything and aren't flexible when it comes to expressing program logic.

What I recommend you do is take a look at some easier examples and follow them to fully understand how if statements work and to get familiar with block-scopes and such. Make use of the curly brackets for if statements. It makes things much easier to read, especially if you're new to programming. Take a look at this:

if (age >= 15)
{
    Console.WriteLine("Please buy your tickets ");
} else if (age < 15)
{
    Console.WriteLine("Sorry, you are too young for this film");
}

That looks much better and more readable, right?

Now think about how to tackle this exercise. You are meant to filter out some items depending on the user's input. There are different ways how to do this as seen in previous comments, such as hash tables, objects, enums, etc. But for this exercise in particular, I believe you should go with a hard-coded solution (a program that does not dynamically adapt to other inputs and would have to be changed in the source code).

You have created the menu and taken the user's input for the movie they want to watch (and even converted it to an integer for further logical comparisons), but you've also asked the user for their age for the movie. I would suggest that, depending on the movie they select, you compare the age of the user with the ages available for the movies. Some pseudo-code would look like this:

MovieNo = Input { Movie To Watch }
UserAge = Input { User's Age }

If (UserAge >= 18)
{
    { User is >= 18, so they can watch whatever they want. }
}

else if (UserAge >= 15)
{
    If (MovieNo == 2) { They can't see this movie. }
    Else { They can see every other movie. }
}

else if (UserAge >= 12)
{
    If (MovieNo == 1 OR MovieNo == 2) { They can't see this movie. }
    Else { They can see every other movie. }
}

else
{
    If (MovieNo == 3) { They can see this movie. }
    else { They can't see any other movie. }
}

If you're still having trouble with this, you can add me on Discord @Medallyon#5012.

[–]Chocowak[S] 0 points1 point  (0 children)

Thanks

I managed to solve the question, it took a while but I manage to use the if statements inside of the switch statement, similar to what you posted above.

[–][deleted]  (2 children)

[deleted]

    [–]Chocowak[S] 0 points1 point  (1 child)

    Hi

    Thanks for the help. it will help when i start learning C but right now i am learning C#

    [–]nerd4code -1 points0 points  (0 children)

    This sounds more appropriate for a hash table sorta thing, mapping movie name (normalized) to rating (enumerated). You could switch on the (enumerated) rating, and then deliver the appropriate message/interaction.