Advertisement
arfin97

UVA - 11945 - FINANCIAL MANAGEMENT

Jan 9th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4.     freopen("in.txt", "r", stdin);
  5.     freopen("out.txt", "w", stdout);
  6.     int tc;
  7.     scanf("%d", &tc);
  8.     int tr;
  9.     for(tr = 1; tr <= tc; tr++){
  10.         double income_per_month = 0.0;
  11.         double income_per_year = 0.0;
  12.         double average_income = 0.0;
  13.         int i;
  14.         for(i = 0; i < 12; i++){
  15.             scanf("%lf", &income_per_month);
  16.             income_per_year += income_per_month;
  17.         }
  18.         average_income = income_per_year / 12.0;
  19. //        double fraction, decimal;
  20. //        fraction = modf(average_income, &decimal);
  21. //        int intpart = decimal;
  22.         double thousand = average_income / 1000;
  23.  
  24.         if(thousand > 0.0){
  25.             int before_commah = average_income/1000;
  26.             double after_commah = average_income - (before_commah*1000);
  27.             printf("%d $%d,%0.2lf\n", tr, before_commah, after_commah);
  28.         }
  29.         else if(thousand <= 0.0){
  30.             printf("%d $%0.2lf\n", tr, average_income);
  31.         }
  32.  
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement