title: C Programming BMI Program
body: <p>Im having trouble using pointers and references with this program. I dont understand it entirely. Im still pretty new at C and we only touched on pointers but haven't gone over it that much. Any help will be appreciated.</p>
  
  <p>EDIT: Now it's not letting me input anything...</p>
  
  <p>Here's my new code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #define F 703
  
  
  int getStats(FILE *statsfp, int *patientID, double *weight, double *height, double *bodymassIndex);
  double getBodyMassIndex(double weight, double height);
  void printWeightStatus(FILE *statsfp, int patientID, double weight, double height, double bodyMassIndex);
  
  
  void pause()
  {
      char ans;
  
      fflush(stdin);
      printf("\nPress return to continue");
      scanf("%c", &amp;ans);
  }
  
  int main() {
  
      FILE statsfp;
      int patientID;
      double weight, height, bodyMassIndex;
  
      getStats(&amp;statsfp,&amp;patientID, &amp;weight, &amp;height, &amp;bodyMassIndex);
  
  
      pause();
      return 0;
  }
  
  int getStats(FILE *statsfp, int *patientID, double *weight, double *height, double *bodyMassIndex)
  {
  
  
  
  
      statsfp = fopen("patientStats.txt","r");
      if (statsfp == NULL)
      {
          printf("\nFailed to open the %s file.\n", "patientStats.txt");
          pause();
          exit(1);
      }
  
      printf("\nPatient ID\t Weight\t Height\t BMI\t Weight Status\n");
      printf("\n---------------------------------------------------\n");
  
  
      while (fscanf (statsfp, "%d %lf %d", &amp;patientID, &amp;weight, &amp;height) !=EOF)
      {
          getBodyMassIndex(*weight, *height);
  
          printWeightStatus(statsfp, *patientID, *weight, *height, *bodyMassIndex);
      }
  
      fclose(statsfp);
  
      return 0;
  
  
  }
  
  double getBodyMassIndex(double weight, double height)
  {
      double bodyMassIndex = 0;
  
      bodyMassIndex = (F*weight)/(height * height);
  
      return bodyMassIndex;
  
  }
  
  void printWeightStatus(FILE *statsfp, int patientID, double weight, double height, double bodyMassIndex)
  {
      char *weightStats;
  
      if (bodyMassIndex &lt; 18.5)
          weightStats = "underweight";
      else if (bodyMassIndex &gt;= 18.5) 
          weightStats = "normal";
      else if (bodyMassIndex &gt;= 25.0)
          weightStats = "overweight";
      else if (bodyMassIndex &gt;= 30.0)
          weightStats = "obese";
  
      printf("%6d\t %6.2f\t %6.2f\t %s", &amp;patientID,&amp;weight, &amp;height, weightStats);
  
  }
  </code></pre>