0% found this document useful (0 votes)
10 views5 pages

Codes of Movies Form

The document is a C program for a Movie Ticket Booking System that allows users to enter movie details, display available movies, and book tickets. It defines a structure for movies, initializes movie data, and provides functions for displaying movies and booking tickets. The program handles user input and manages seat availability for each movie.

Uploaded by

rajaian9823
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Codes of Movies Form

The document is a C program for a Movie Ticket Booking System that allows users to enter movie details, display available movies, and book tickets. It defines a structure for movies, initializes movie data, and provides functions for displaying movies and booking tickets. The program handles user input and manages seat availability for each movie.

Uploaded by

rajaian9823
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <stdio.

h>

#include <stdlib.h>

#include <string.h>

#define MAX_MOVIES 10

#define MAX_NAME_LENGTH 50

#define MAX_SEATS 50

// Structure to represent a movie

typedef struct {

char tle[MAX_NAME_LENGTH];

char genre[MAX_NAME_LENGTH];

int dura on; // in minutes

int seats[MAX_SEATS];

} Movie;

// Func on prototypes

void ini alizeMovies(Movie movies[], int numMovies);

void displayMovies(Movie movies[], int numMovies);

void bookTicket(Movie movies[], int numMovies);

int main() {

Movie movies[MAX_MOVIES];

int numMovies;

prin ("Welcome to the Movie Ticket Booking System\n\n");

prin ("Enter the number of movies available: ");

scanf("%d", &numMovies);

getchar(); // Clear the input buffer

ini alizeMovies(movies, numMovies);


int choice;

do {

prin ("\n1. Display available movies\n");

prin ("2. Book a cket\n");

prin ("3. Exit\n");

prin ("Enter your choice: ");

scanf("%d", &choice);

switch (choice) {

case 1:

displayMovies(movies, numMovies);

break;

case 2:

bookTicket(movies, numMovies);

break;

case 3:

prin ("Thank you for using the Movie Ticket Booking System.\n");

break;

default:

prin ("Invalid choice. Please try again.\n");

} while (choice != 3);

return 0;

// Func on to ini alize movie data

void ini alizeMovies(Movie movies[], int numMovies) {

for (int i = 0; i < numMovies; i++) {

prin ("\nEnter details for Movie %d:\n", i + 1);


prin ("Title: ");

getchar(); // clear the newline from buffer

fgets(movies[i]. tle, MAX_NAME_LENGTH, stdin);

movies[i]. tle[strcspn(movies[i]. tle, "\n")] = 0; // Remove newline character

prin ("Genre: ");

fgets(movies[i].genre, MAX_NAME_LENGTH, stdin);

movies[i].genre[strcspn(movies[i].genre, "\n")] = 0; // Remove newline character

prin ("Dura on (in minutes): ");

scanf("%d", &movies[i].dura on);

for (int j = 0; j < MAX_SEATS; j++) {

movies[i].seats[j] = 0; // Ini alize all seats to available

// Func on to display available movies

void displayMovies(Movie movies[], int numMovies) {

prin ("\nAvailable Movies:\n");

for (int i = 0; i < numMovies; i++) {

prin ("%d. %s (%s, %d mins)\n", i + 1, movies[i]. tle, movies[i].genre, movies[i].dura on);

// Func on to book a cket

void bookTicket(Movie movies[], int numMovies) {

int movieChoice, numSeats;

prin ("\nEnter the movie number: ");

scanf("%d", &movieChoice);

prin ("Enter the number of seats: ");

scanf("%d", &numSeats);
// Check if movie choice is valid

if (movieChoice < 1 || movieChoice > numMovies) {

prin ("Invalid movie choice.\n");

return;

// Check if there are enough available seats

int availableSeats = 0;

for (int i = 0; i < MAX_SEATS; i++) {

if (movies[movieChoice - 1].seats[i] == 0) {

availableSeats++;

if (availableSeats < numSeats) {

prin ("Not enough available seats.\n");

return;

// Book the seats

prin ("Enter seat numbers (1-%d) separated by spaces: ", MAX_SEATS);

int seat;

for (int i = 0; i < numSeats; i++) {

scanf("%d", &seat);

if (seat < 1 || seat > MAX_SEATS || movies[movieChoice - 1].seats[seat - 1] == 1) {

prin ("Invalid or already booked seat number %d.\n", seat);

i--; // Retry the current seat input

} else {

movies[movieChoice - 1].seats[seat - 1] = 1;

}
prin ("Booking successful!\n");

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy