Code:
#include <stdio.h>
3 #define beg_population 52.966
4 #define growth_rate 2.184
5 #define beg_year 1990
6 double population();
7 int main()
8 {
9
10 population();
11 double pred_pop;
12 pred_pop=population();
13
14 FILE *fp;
15 fp= fopen("pop.txt", "w");
16 fprintf(fp,"%lf",pred_pop);
17 fscanf(fp,"%lf", &pred_pop);
18 fclose(fp);
19 return 0;
20 }// main
21
22
23
24 double population()
25 {
26
27 printf("Enter a year after 1990> ");
28 double year;
29 scanf("%lf",&year);
30 printf("Predicted Gotham City population is %lf (in thousands) : %lf ", year, population());
31 return beg_population+growth_rate*(year-beg_year);
32
33 } // population function
it keeps looping the same statement
"Enter a year after 1990>
"Enter a year after 1990>
"Enter a year after 1990>
I believe that the year i entered is stored in population function.
Is my program completely messed up? Or it is there a simple fix?
whereas pred_pop= predicted population
basically what i want to do is write the result of the function population into the file pop.txt.