Advertisement
thenewboston

C Programming Tutorial - 16 - Typecasting

Aug 22nd, 2014
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     float avgProfit;
  7.     int priceOfPumpkin = 10;
  8.     int sales = 59;
  9.     int daysWorked = 7;
  10.  
  11.     //wont work
  12.     avgProfit = ( priceOfPumpkin * sales) / daysWorked;
  13.     //temporarily changes ints to floats
  14.     avgProfit = ( (float)priceOfPumpkin * (float)sales) / (float)daysWorked;
  15.     printf("Age daily profit of: $%.2f", avgProfit);
  16.  
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement