And I am trying to output first part of text which is 135 which is the goal weight. This is how it is supposed to output:
Progress Report After 5 weeks
----------------------------------------
Goal Weight: 135 lbs
Total Weight Lost: 11.0 lbs
Min lost in a week: 0.5 lbs
Max lost in a week: 5.4 lbs
Avg weight lost per week: 2.2 lb
Weight Goal is not met yet
Weight still to be lost: 11.4 lbs
Please use code tags they are the <> under format. Also that is C code not C++, are you aware of that? I ask because I seen a few people post code like that and thought it was C++ and it wasnt, so just want to make sure your not learning the wrong code.
I have this so far, but I am having a hard time figuring out the average or how to get about it in C.
#include <stdio.h>
int main(){
FILE * filePtr = NULL;
/* Name of file I am creating */
char * weigh = "Weightlog.txt";
// Creating file for weightlog
filePtr = fopen(weigh, "w");
/* Data for the text file */
fprintf(filePtr, "135\n");
fprintf(filePtr, "5\n");
fprintf(filePtr, "158.2 157.5\n");
fprintf(filePtr, "157.0 156.5\n");
fprintf(filePtr, "156.6 151.2\n");
fprintf(filePtr, "151.0 148.9\n");
fprintf(filePtr, "148.7 146.4\n");
fprintf(filePtr, "0\n");
/* Now lets close the file, so we can open it again in read mode safely */
fclose(filePtr);
/* Reading file */
filePtr = fopen(weigh, "r");
/* Get the first number and print it off */
int goal = 0;
fscanf(filePtr, "%d", &goal);
printf("Progress Report After 5 weeks\n");
printf("-----------------------------\n");
printf("Goal Weight: %d lbs\n", goal);