Home Segments Index Top Previous Next

490: Mainline

The first step toward improving the output would be to replace the industry codes with industry names, thus producing a report such as the following:

Food 3.300000 300 990.000000 
Trucking 2.500000 400 1000.000000 
Airline 9.900000 100 990.000000 
Airline 10.100000 100 1010.000000 
Computers 5.000000 200 1000.000000 

One way to have analyze_trades do the required work is to introduce a function, display_industry_name, that displays an industry name when given a trade object, as determined by the enumeration constants for the various industries:

void display_industry_name (struct trade *t) { 
  switch (t -> industry) { 
    case food:          printf ("Food");        break; 
    case trucking:      printf ("Trucking");    break; 
    case computers:     printf ("Computers");   break; 
    case metals:        printf ("Metals");      break; 
    case health:        printf ("Health");      break; 
    case airline:       printf ("Airline");     break; 
    default:            printf ("Unknown");     break; 
  } 
} 

Given display_industry_name, you could revise the information-displaying statement:

for (counter = 0; counter < limit; ++counter) { 
  display_industry_name (trade_pointers[counter]); 
  printf (" %f %i %f\n", 
          trade_pointers[counter] -> price, 
          trade_pointers[counter] -> number, 
          trade_price(trade_pointers[counter])); 
}