Cinema Access
Using if and else statements; make a program that prompts the user to input their age and what movie they want to watch.
Give them access to the movie by outputting "Welcome!" if they are old enough to watch the movie. Deny them access to the movie by outputting "You are too young to watch the movie" if they aren't old enough.
Only ask for the users age if they are watching a movie with an age limit.
Movies: & Rating
- Finding Nemo (No age limit)
- Inception (13+)
- The Revenant (18+)
- Mission Impossible (13+)
Hint
You can ask what movie they want to watch by listing the movies with an "index". If the user inputs 1, they want to watch Finding nemo. If it's 2, they want to watch Inception, etc.
Answer
#include <iostream>
int main()
{
std::cout << "What movie do you want to watch?\n";
std::cout << "1 = Finding Nemo.\n";
std::cout << "2 = Inception.\n";
std::cout << "3 = The Revenant.\n";
std::cout << "4 = Mission Impossible.\n";
int movie_id;
std::cin >> movie_id;
// If the user wants to watch Finding Nemo
if (movie_id == 1)
{
// No age limit, so you don't have to check the age
std::cout << "Welcome!\n";
}
// If the user wants to watch Inception
if (movie_id == 2)
{
std::cout << "How old are you?\n";
int age;
std::cin >> age;
if (age >= 13)
{
std::cout << "Welcome!\n";
}
else
{
std::cout << "Sorry, you are too young to watch this movie.\n";
}
}
// If the user wants to watch The Revenant
if (movie_id == 3)
{
std::cout << "How old are you?\n";
int age;
std::cin >> age;
if (age >= 18)
{
std::cout << "Welcome!\n";
}
else
{
std::cout << "Sorry, you are too young to watch this movie.\n";
}
}
// If the user wants to watch Mission Impossible
if (movie_id == 4)
{
std::cout << "How old are you?\n";
int age;
std::cin >> age;
if (age >= 13)
{
std::cout << "Welcome!\n";
}
else
{
std::cout << "Sorry, you are too young to watch this movie.\n";
}
}
}