Home Segments Index Top Previous Next

212: Mainline

Thus, the following program computes trade values as you type price-per-share–number-of-shares pairs; it stops when you type the control-d keychord:

#include  
double trade_price (double p, int n) { 
  return p * n; 
} 
main ( ) { 
  double price; 
  int number; 
  while (2 == scanf ("%lf%i", &price, &number)) 
    printf ("The total price of the trade is %f.\n", 
            trade_price (price, number)); 
} 
--- Data ---
2.5 500 7.5 500 
--- Result --- 
The total price of the trade is 1250.000000. 
The total price of the trade is 3750.000000.