Advertisement
bakerboy908

Untitled

Apr 23rd, 2019
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.94 KB | None | 0 0
  1. void print_menu (void)
  2. {
  3.     printf("\n");
  4.      printf("1. add a flight\n");
  5.      printf("2. display all flights to a destination\n");
  6.      printf("3. save the flights to the database file\n");
  7.      printf("4. load the flights from the database file\n");
  8.      printf("5. exit the program\n");
  9.      printf("Enter choice (number between 1-5)>\n");
  10. }
  11.  
  12. flights_t add_flight(index)
  13. {
  14.     /* Set up a verable for getting data */
  15.     flights_t temp_flight;
  16.     int j,i=0;
  17.  
  18.     /* in array for flights is full do not add more. */
  19.     if(index >= MAX_NUM_FLIGHTS)
  20.     {
  21.         printf("Cannot add more flights - memory full\n");
  22.         return temp_flight;
  23.     }
  24.  
  25.  
  26.     /* Scan in flight code one char at a time */
  27.     printf("Enter flgiht code>\n");
  28.     for(j=0; j<MAX_FLIGHTCODE_LEN-1; j++)
  29.     {
  30.             scanf("%c", &temp_flight.flightcode[j]);
  31.     }
  32.     temp_flight.flightcode[i] = '\0';
  33.    fflush(stdin);
  34.  
  35.    printf("Flight code entered: %s\n", temp_flight.flightcode);  
  36.    
  37.     printf("Enter depature info for the flight leaving sydney.\n");    
  38.     while (i ==0)
  39.     {    
  40.         printf("Enter month, date , hour and minute separated by spaces>\n");
  41.     /* scan in depature time in formate day month hour year */
  42.         scanf("%d",&temp_flight.departure_dt.month);
  43.         scanf("%d",&temp_flight.departure_dt.day);
  44.         scanf("%d",&temp_flight.departure_dt.hour);
  45.         scanf("%d",&temp_flight.departure_dt.minute);
  46.         if(valid_input(3,temp_flight)==0)
  47.         {
  48.             printf("Valid date\n");
  49.             i++;
  50.         }
  51.         else
  52.         {
  53.             printf("invalid date\n");
  54.       }
  55.     }
  56.      fflush(stdin);
  57.    i=0;
  58.     /* Scan in arrival city code on char at a time */
  59.     while(i==0)
  60.     {
  61.         printf("Enter arrival city code>\n");
  62.         for(j=0;j<MAX_CITYCODE_LEN-1;j++)
  63.         {
  64.  
  65.                 scanf(" %c",&temp_flight.arrival_city[j]);
  66.  
  67.  
  68.             temp_flight.arrival_city[j] = '\0';
  69.  
  70.                    
  71.            
  72.         }
  73.         printf("City code entered: %s\n", temp_flight.arrival_city);  
  74.         if(valid_input(4, temp_flight)==0)
  75.         {
  76.             printf("Valid input\n");
  77.             i++;
  78.         }
  79.         else
  80.         {
  81.             printf("invalid input\n");
  82.         }
  83.        
  84.     }
  85.     i=0;
  86.     /* Scan in arival date and time */
  87.    fflush(stdin);
  88.  
  89.     printf("Enter arrival info.\n");    
  90.     while(i==0)
  91.     {
  92.         printf("Enter month, date, hour and minute separated by spaces>\n");
  93.         scanf(" %d",&temp_flight.arrival_dt.month);
  94.         scanf(" %d",&temp_flight.arrival_dt.day);
  95.         scanf(" %d",&temp_flight.arrival_dt.hour);
  96.         scanf(" %d",&temp_flight.arrival_dt.minute);
  97.  
  98.         if(valid_input(2,temp_flight)==0)
  99.         {
  100.             printf("Valid date\n");
  101.             i++;
  102.         }
  103.         else
  104.         {
  105.             printf("invalid date\n");
  106.         }
  107.     }
  108.    fflush(stdin);
  109.  return temp_flight;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement