In: Computer Science
Can anyone translate this to flowgorith.
#include<stdio.h>
int main()
{
int seatingChart[10];
//array for seating chart
int fc = 0, ec = 5,i;
//starting positions for first class and economy class
printf("Welcome to the Airline Reservation System
(ARS)\n\n");
for(i=0;i<10;i++)
//initializing the array with zero
{
seatingChart[i] = 0;
}
char choice;
do
{
int ch;
printf("Please type 1 for first
class\nPlease type 2 for economy: ");
//taking the input from the user
fflush(stdin);
scanf("%d",&ch);
if(ch == 1 && fc <=
4)
{
//checking
the conditions to assign the seating
seatingChart[fc]
= 1;
//if 1 entered and first class is empy then seat
is reserved
printf("Seat
number %d reserved (first class)\n",fc+1);
fc++;
}
else if(ch == 1 && fc >
4 && ec<=9) //if fist
class is not empty and economy class is empty
{
char
check;
printf("First
class is filld.Do you want reserve for Economy Section (y/n)?
"); //asking the user to
confirm
fflush(stdin);
scanf("%c",&check);
if(check ==
'y') //if yes assigning the economy
class
{
seatingChart[ec] = 1;
printf("Seat number %d reserved (first
class)\n",ec+1);
ec++;
}
else
{
printf("Next flight leaves in 3
hours.\n");
}
}
else if(ch == 2 && ec <=
9) //if 2 is entered and economy
class is avaiable
{
seatingChart[ec]
= 1;
printf("Seat
number %d reserved (first class)\n",ec+1);
ec++;
}
else if(ch == 2 && ec >
9 && fc <= 4)
//if economy class is not availale and
{
//first class is
available
char
check;
printf("Economy
Section is filld.Do you want reserve for First Class (y/n)?
");
fflush(stdin);
scanf("%c",&check);
if(check ==
'y')
{
seatingChart[fc] = 1;
printf("Seat number %d
reserved (first class)\n",fc+1);
fc++;
}
else
{
printf("Next flight leaves in 3
hours.\n");
}
}
else
{
printf("Next
flight leaves in 3 hours.\n"); //if
both are not available
}
printf("Seat Assignments: FC:
"); //printing the seats avalable
for(i=0;i<5;i++)
{
if(seatingChart[i] == 1)
{
printf("X ");
}
else
{
printf("_ ");
}
}
printf("EC: ");
for(i=5;i<10;i++)
{
if(seatingChart[i] == 1)
{
printf("X ");
}
else
{
printf("_ ");
}
}
printf("\n\t\t 1 2 3 4 5 6 7 8 9
10\n");
printf("Another reservation
(y/n)? "); //asking if the user
wants to make an other reservation
fflush(stdin);
scanf("%c",&choice);
}
while(choice == 'y');
return 0;
}
I have tried and can't get it to work.
#include<stdio.h>
int main()
{
int seatingChart[10];
//array for seating chart
int fc = 0, ec = 5,i,p;
//starting positions for first class and economy class
printf("Welcome to the Airline Reservation System
(ARS)\n\n");
for(i=0;i<10;i++)
//initializing the array with zero
{
seatingChart[i] = 0;
}
int ch;
for( int j = 0; j< 10; j++)
{
printf("Please type 1 for first class\nPlease type 2 for economy: "); //taking the input from the user
scanf("%i",&ch);
switch(ch)
{
case 1:
printf("\nFirst class\n");
printf("Seats available are 1,2,3,4,5.\n");
do
{
printf("Pick a seat:\n\n");
scanf("%i",&p);
seatingChart[j]=p;
for (i=0; i<j; i++)
{
if (seatingChart[j]==seatingChart[i])
{
printf("\n\nSeat taken.\n\n");
break;
}
}
}
while (i!=j);
if(seatingChart[j] <= 5)
{
printf("\n");
printf("--------------------------\n");
printf("Class: First class\n");
printf("Seat no : %i\n",seatingChart[j]);
printf("--------------------------\n\n");
}
else
printf("Next flight leaves in 3 hours.\n");
break;
case 2:
printf("\nEconomical class\n");
printf("Seats
available are 6,7,8,9,10.\n");
do
{
printf("Pick a seat:\n\n");
scanf("%i",&p);
seatingChart[j]=p;
for (i=0;
i<j; i++)
{
if (seatingChart[j]==seatingChart[i])
{
printf("\n\nSeat taken.\n\n");
break;
}
}
}
while (i!=j);
if(seatingChart[j] >= 6)
{
printf("\n");
printf("--------------------------\n");
printf("Class: Economical class\n");
printf("Seat no : %i\n",seatingChart[j]);
printf("--------------------------\n\n");
}
else
printf("Next flight leaves in 3 hours.\n");
break;
default:
break;
}//end switch case
}//end counting people*/
return 0;
}