After my program writes to a text file, I am getting strange characters. For example:
Enter Weight in Pounds and Height in Inches: ÍÍÍÍYour BMI is: 25.11
Overweight
These "ÍÍÍÍ" should be numbers i.e. : 170 70.
Has anyone else come upon this problem? If you need to see my code here it is.
#include <stdio.h>
#include <stdlib.h>
FILE *fp;
void Calculate_BMI(double Weight_in_Pounds, double Hieght_in_Inches, double BMI);
int main()
{
fp = fopen("csis.txt", "w");
int i;
double Wieght_in_Pounds, Hieght_in_Inches, BMI;
Wieght_in_Pounds = 0;
Hieght_in_Inches = 0;
BMI = 0;
for (i = 1; i <= 4; ++i) {
Calculate_BMI(Wieght_in_Pounds, Hieght_in_Inches, BMI);
}
fclose(fp);
system("pause");
return(0);
}
void Calculate_BMI(double Weight_in_Pounds, double Hieght_in_Inches, double
BMI)
{
printf("Enter Weight in Pounds and Hieght in Inches: ");
fprintf(fp, "Enter Weight in Pounds and Hieght in Inches: ");
scanf(" %lf %lf", &Weight_in_Pounds, &Hieght_in_Inches);
fscanf(fp, " %lf %lf", &Weight_in_Pounds, &Hieght_in_Inches);
BMI = (Weight_in_Pounds * 703) / (Hieght_in_Inches * Hieght_in_Inches);
printf("Your BMI is: %3.2lf\n", BMI);
fprintf(fp, "Your BMI is: %3.2lf\n", BMI);
if (BMI < 18.5) {
printf("Under Weight\n");
fprintf(fp, "Under Weight\n");
}
else if (BMI >= 18.5, BMI <= 25.0){
printf("Normal weight\n");
fprintf(fp, "Normal weight\n");
}
else if (BMI >= 25.0, BMI <= 30.0) {
printf("Overweight\n");
fprintf(fp, "Overweight\n");
}
else {
printf("Obese\n");
fprintf(fp, "Obese\n");
}
}