At this point, the analyze_trades
program is reduced to displaying a
straightforward report so as to provide a simpler base on which to build
more C mechanisms. On the other hand, the trade structure is enriched to
enable trade
objects to retain an industry-encoding integer:
#include/* Define the trade apparatus */ struct trade {double price; int number; int industry;}; /* Define trade array */ struct trade *trade_pointers[100]; /* Define price-computing function */ double trade_price (struct trade *x) { return x -> price * x -> number; } main ( ) { /* Declare various variables */ int limit, counter, number, industry; double price; /* Read trade information */ for (limit = 0; 3 == scanf ("%i%lf%i", &industry, &price, &number); ++limit) { trade_pointers[limit] = (struct trade*) malloc (sizeof (struct trade)); trade_pointers[limit] -> price = price; trade_pointers[limit] -> number = number; trade_pointers[limit] -> industry = industry; } /* Display report */ for (counter = 0; counter < limit; ++counter) printf ("%i %f %i %f\n", trade_pointers[counter] -> industry, trade_pointers[counter] -> price, trade_pointers[counter] -> number, trade_price(trade_pointers[counter])); }
As you can see, the purpose of this analyze_trades
program is to
regurgitate the information supplied for each trade, with the addition of a
trade-price column.