title: C programming: why are my decimals not displaying & how do I define black spaces
body: <p>I'm learning basic C for an Introductory Programming class that I'm taking and I have two questions related to the code below.</p>
  
  <p>First: in the <code>//calculations</code> section, I want my values called <code>cryr1</code>, <code>cryr2</code>, <code>cryr3</code>, and <code>avgcr</code>, to display the results out to 2 decimal places. I'm only getting whole numbers with 2 decimals places. QUESTION: Is there something wrong in how I wrote my calculations?</p>
  
  <p>Second: in the section where I have all my <code>printf</code> statements, I have a lot of empty white spaces to support the spacing in the table that I want to render. However, if the inputs to this output vary in numerical length, the columns don't render properly. QUESTION: Is there some code or syntax that I should use that calculates or determines the number spaces that each value in the table show appear?</p>
  
  <pre><code>// Global Variable declarations
  FILE *reportfile;                // report file (for output) 
  FILE *inputfile;                 // disk file (for input)    
  char company[31];                // company name             
  int assetsyr1;                   // assets year 1            
  int assetsyr2;                   // assets year 2
  int assetsyr3;                   // assets year 3
  int liabilitiesyr1;              // liabilties year 1
  int liabilitiesyr2;              // liabilties year 2
  int liabilitiesyr3;              // liabilities year 3
  float cryr1;                     // current ratio yr1
  float cryr2;                     // current ratio yr2
  float cryr3;                     // current ratio yr3
  float avgassets;                 // average assets
  float avgliabilities;            // average liabilities
  float avgcr;                     // average current ratio
  
  
  //calculations
  cryr1 = (assetsyr1/liabilitiesyr1);
  cryr2 = (assetsyr2/liabilitiesyr2);
  cryr3 = (assetsyr3/liabilitiesyr3);
  avgassets = (assetsyr1 + assetsyr2 + assetsyr3)/3;
  avgliabilities = (liabilitiesyr1 + liabilitiesyr2 + liabilitiesyr3)/3;
  avgcr = (cryr1 + cryr2 + cryr3)/3;
  
  
  printf("%s\Current Ratio Report\n\n", company);
  printf("                Current           Current          Current\n");
  printf("Year            Assets            Liabilities      Ratio\n");
  printf("----------------------------------------------------------\n");
  printf("2010              %d             %d             %1.2f\n", assetsyr1, liabilitiesyr1, cryr1);
  printf("2011              %d              %d             %1.2f\n", assetsyr2, liabilitiesyr2, cryr2);
  printf("2012              %d             %d             %1.2f\n", assetsyr3, liabilitiesyr3, cryr3);
  printf("----------------------------------------------------------\n");
  printf("Average           %1.0f             %1.0f             %1.2f\n\n", avgassets, avgliabilities, avgcr);
  </code></pre>
  
  <p>The image is supposed to render like this</p>
  
  <p><a href="https://i.stack.imgur.com/ZHzOR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZHzOR.png" alt="expected output"></a></p>
  
  <p>Any help you can offer is much appreciated. Thank you, David</p>
  
  <p>I've placed the source code and input file <a href="https://drive.google.com/drive/folders/0B9zdJQ7M_lvWeWxkeFEyUHpiaEE?usp=sharing" rel="nofollow noreferrer">here</a></p>