Home Segments Index Top Previous Next

216: Mainline

The for reading pattern is at work in the following amended version of the program in Segment 212:

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