Translate the code over to be able to use in C (using sanf and printf) #include
ID: 3762487 • Letter: T
Question
Translate the code over to be able to use in C (using sanf and printf)
#include <stdio.h>
//Function Declarations
int Show_Menu (); //To show main menu
void Show_Chart (); //To show seating chart
const char FULL = '*'; //Seat taken
const char EMPTY = '#'; //Seat open
const int rows = 15; //Number of rows
const int columns = 30; //Number of seats per row
char map [rows][columns]; //Array to hold seating chart
double price;
int total = 0;
int seat = 450;
int seat2 = 0;
int Quit = 1;
int main ()
{
const int Num_Rows = 15;
int price [Num_Rows];
int row2, column2, cost;
int answer;
//Main Logo
printf( " *********************************************************" );
printf( " * *" );
printf( " * Welcome to The our small town Theater *" );
printf( " * *" );
printf( " *********************************************************" );
printf(“ ”);
//Sets the row prices.
int count,i;
for (count = 0; count < rows; count++)
{
printf( "Please enter the price for row " << (count + 1)<< ": ";
scanf( price [count];
}
for (i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
map [i][j] = EMPTY;
}
int choice;
do
{
choice = Show_Menu(); // Shows the main menu function.
switch (choice)
{
case 1:
printf( "View Seat Prices ";
for (count = 0; count < rows; count++)
{
printf( "The price for row %d :”, (count + 1) );
printf( “%d”,price [count] );
}
break;
case 2:
printf( "Purchase a Ticket ”);
do
{
printf( "Please select the row you would like to sit in: “);
scanf( “%d”,&row2);
printf( "Please select the seat you would like to sit in: ";
scanf(“%d”,&column2);
if (map [row2] [column2] == '*')
{
printf( "Sorry that seat is sold-out, Please select a new seat.”);
}
else
{
cost = price [row2] + 0;
total = total + cost;
printf( "That ticket costs: %d “, cost );
printf( "Confirm Purchase? Enter (1 = YES / 2 = NO)”);
scanf(“%c”, answer);
seat = seat - answer;
seat2 += answer;
if (answer == 1)
{
printf( "Your ticket purchase has been confirmed." );
map [row2][column2] = FULL;
}
else if (answer == 2)
{
printf( "Would you like to look at another seat? (1 = YES / 2 = NO)";
scanf( “%c”,Quit);
}
printf( "Would you like to look at another seat?(1 = YES / 2 = NO)";
scanf( “%c”,Quit);
}
}
while (Quit == 1);
break;
case 3:
printf( "View Available Seats ";
Show_Chart ();
break;
case 4:
printf( "View Seat Sales ";
break;
case 5:
printf( "quit ";
break;
default : printf( "Error input ";
}
} while (choice != 5);
return 0;
}
//********************************************************************************
//********************************************************************************
//** **
//** Define Functions. **
//** **
//********************************************************************************
//********************************************************************************
// Show Menu Function...
int Show_Menu()
{
int MenuChoice;
printf( endl );
printf( " MAIN MENU ";
printf( " 1. View Seat Prices. ";
printf( " 2. Purchase a Ticket. ";
printf( " 3. View Available Seats. ";
printf( " 4. View Ticket Sales. ";
printf( " 5. Quit the program. ";
printf( "_____________________ ";
printf( "Please enter your choice: ";
scanf( MenuChoice;
printf( endl );
return MenuChoice;
}
//Show Seating Chart Function
void Show_Chart ()
{
printf( " Seats" );
printf( " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ";
for (int count = 0; count < 15; count++)
{
printf( endl << "Row " << (count + 1);
for (int count2 = 0; count2 < 30; count2++)
{
printf( " " << map [count] [count2];
}
}
printf( endl;
}
Explanation / Answer
#include <stdio.h>
//Function Declarations
int Show_Menu (); //To show main menu
void Show_Chart (); //To show seating chart
const char FULL = '*'; //Seat taken
const char EMPTY = '#'; //Seat open
const int rows = 15; //Number of rows
const int columns = 30; //Number of seats per row
char map [rows][columns]; //Array to hold seating chart
double price;
int total = 0;
int seat = 450;
int seat2 = 0;
int Quit = 1;
int main ()
{
const int Num_Rows = 15;
int price [Num_Rows];
int row2, column2, cost;
int answer;
//Main Logo
printf( " ********************************************************* " );
printf( " * *" );
printf( " * Welcome to The our small town Theater *" );
printf( " * * " );
printf( " *********************************************************" );
printf(" ");
//Sets the row prices.
int count,i;
for (count = 0; count < rows; count++)
{
printf( "Please enter the price for row %d: ", (count + 1));
scanf( "%d", &price [count]);
}
for (i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
map [i][j] = EMPTY;
}
int choice;
do
{
choice = Show_Menu(); // Shows the main menu function.
switch (choice)
{
case 1:
printf( "View Seat Prices ");
for (count = 0; count < rows; count++)
{
printf( "The price for row %d :", (count + 1) );
printf( "%d",price [count] );
}
break;
case 2:
printf("Purchase a Ticket ");
do
{
printf( "Please select the row you would like to sit in: ");
scanf( "%d",&row2);
printf( "Please select the seat you would like to sit in: ");
scanf("%d",&column2);
if (map [row2] [column2] == '*')
{
printf( "Sorry that seat is sold-out, Please select a new seat.");
}
else
{
cost = price [row2] + 0;
total = total + cost;
printf( "That ticket costs: %d ", cost );
printf( "Confirm Purchase? Enter (1 = YES / 2 = NO)");
scanf(" %d", &answer);
seat = seat - answer;
seat2 += answer;
if (answer == 1)
{
printf( "Your ticket purchase has been confirmed." );
map [row2][column2] = FULL;
}
else if (answer == 2)
{
printf( "Would you like to look at another seat? (1 = YES / 2 = NO)");
scanf( "%d",&Quit);
}
printf( "Would you like to look at another seat?(1 = YES / 2 = NO)");
scanf( "%d",&Quit);
}
}
while (Quit == 1);
break;
case 3:
printf( "View Available Seats ");
Show_Chart ();
break;
case 4:
printf( "View Seat Sales ");
break;
case 5:
printf( "quit ");
break;
default : printf( "Error input ");
}
} while (choice != 5);
return 0;
}
//********************************************************************************
//********************************************************************************
//** **
//** Define Functions. **
//** **
//********************************************************************************
//********************************************************************************
// Show Menu Function...
int Show_Menu()
{
int MenuChoice;
printf( " " );
printf( " MAIN MENU ");
printf( " 1. View Seat Prices. ");
printf( " 2. Purchase a Ticket. ");
printf( " 3. View Available Seats. ");
printf( " 4. View Ticket Sales. ");
printf( " 5. Quit the program. ");
printf( "_____________________ ");
printf( "Please enter your choice: ");
scanf("%d", &MenuChoice);
printf( " " );
return MenuChoice;
}
//Show Seating Chart Function
void Show_Chart ()
{
printf( " Seats" );
printf( " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ");
for (int count = 0; count < 15; count++)
{
printf( " Row %d", (count + 1));
for (int count2 = 0; count2 < 30; count2++)
{
printf( "%d" , map[count][count2]);
}
}
printf( " ");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.