Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Help me please update my program

0 votes
asked Mar 30, 2018 by Олександр Ломако (230 points)
Here is the task and program code

Write a program for a company that sells plane tickets. Believe that the airplane makes a flight on the route Kiev-Lviv five times a day. Each aircraft has 10 seats. The passenger must be able to indicate the flight number and the number of places required. The program must either sell the required number of tickets or indicate that there is no required number of tickets for the specified flight. Assume two-dimensional array (5x10) in the program

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

#include <iostream>

char arr[5][10];

int arr1[10]={1,2,3,4,5,6,7,8,9,10},x,y;

void tabl(){

int i,j;

printf("Number of seats|");

for(int k=0; k<10; k++){

printf("  %d ",arr1[k]);

}

printf("\n----------------------------------------------------------\n");

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

printf("   Flight #%d   |  ",i+1);

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

arr[i][j]='-';

printf("%c   ",arr[i][j]);

}

printf("\n");

}

printf("----------------------------------------------------------\n");

}

void vvod(){

printf("Choose a flight: ");

scanf("%d",&x);

while(x<1||x>5){

printf("Choose a correct flight: ");

scanf("%d",&x);

}

printf("Number of tickets: ");

scanf("%d",&y);

while(y<1||y>10){

printf("Enter correct number of tickets: ");

scanf("%d",&y);

}

}

int main(){

int i,j,k,r,p;

int m[5]={0,0,0,0,0};

tabl();

while(1){

vvod();

printf("number of seats|");

for(k=0; k<10; k++){

printf("  %d ",arr1[k]);

}printf("\n----------------------------------------------------------\n");

for(i=0; i<5; i++){

    printf("   Flight #%d   |  ",i+1);

for(j=0; j<10; j++){

for(p=0; p<y; p++){

    r=p+m[x-1];

    arr[x-1][r]='#';

    }

printf("%c   ",arr[i][j]);

} printf("\n");

}m[x-1]+=y;

printf("----------------------------------------------------------\n");

}

printf("\n");

return 0;

}

.

1 Answer

+1 vote
answered Apr 2, 2018 by Yog
Hello, This is updated code by me.

// http://question.onlinegdb.com/1160/help-me-please-update-my-program?show=1160#q1160

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

char arr[5][10] = { {'-','-','-','-','-','-','-','-','-','-'},

{'-','-','-','-','-','-','-','-','-','-'},

{'-','-','-','-','-','-','-','-','-','-'},

{'-','-','-','-','-','-','-','-','-','-'},

{'-','-','-','-','-','-','-','-','-','-'},

};

int x,y,Tickets_Count = 0;

void tabl()

{

int i,j;

printf("Number of seats|");

for(int k = 1; k <= 10; k++)

{

printf("  %d ",k);

}

printf("\n----------------------------------------------------------\n");

for(int i = 0; i < 5; i++)

{

printf("   Flight #%d   |  ",i+1);

for(int j = 0; j < 10; j++)

{

printf("%c   ",arr[i][j]);

}

printf("\n");

}

printf("----------------------------------------------------------\n");

}

void vvod()

{

printf("Choose a flight: ");

scanf("%d",&x);

x -= 1;

while((x < 0) || (x > 4))

{

printf("Choose a correct flight: ");

scanf("%d",&x);

x -= 1;

}

printf("Number of tickets: ");

scanf("%d",&y);

while((y < 1) || (y > 10))

{

printf("Enter correct number of tickets: ");

scanf("%d",&y);

}

}

int main()

{

int i,j,count;

tabl();

while(1)

{

vvod();

count = 0;

for(i = 0; i < 10; i++)

{

if(arr[x][i] == '-')

count++;

}

if(count >= y)

{

for(i = 0 ; i < 10 ; i++)

{

if(arr[x][i] == '-')

break;

}

for(   ;  y > 0 ; i++, y--)

{

arr[x][i] = '#';

Tickets_Count ++;

}

}

else

{

printf("Entered Number of tickets Not Available\n");

}

printf("----------------------------------------------------------\n");

tabl();

if(Tickets_Count == 50)

{

printf("\n* * * * * All The Flight are Full. * * * * * \n\t\tThanks You\n ");

while(1);

}

}

printf("\n");

return 0;

}
commented Apr 3, 2018 by Олександр Ломако (230 points)
Thank you very much!
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...