Home Segments Index Top Previous Next

675: Mainline

In the main function, you can arrange to include the mean-size calculation only if the value of mode indicates that you are not in a hurry:

main ( ) { 
  /* Declare various variables */ 
  int limit, counter, number; 
  double price; 
  /* Read numbers from the file and stuff them into array */ 
  for (limit = 0; 
       2 == scanf ("%lf%i", &price, &number); 
       ++limit) { 
    trade_pointers[limit]  
      = (struct trade*) malloc (sizeof (struct trade)); 
    trade_pointers[limit] -> price = price; 
    trade_pointers[limit] -> number = number; 
  } 
  /* Perform analysis */ 
  printf ("The mean price per share of the trades is %.2f.\n", 
          mean_price (trade_pointers, limit)); 
  if (mode != fast) 
    printf ("The mean number of shares traded is %.0f.\n", 
            mean_size (trade_pointers, limit)); 
}