i am trying to do a program like a weight lost program
so it will take in value such as the BMR and show how much you have eaten extra and according to that i need to add the excess into the current weight, my program work untill the switch part, i have problem in the (if ,if else part) only the first if work the rest doesn't. please help me!
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
float curweight;
float *pcurweight = &curweight;
float idealweight;
float burn;
float daily;
float lostweight;
float howmuchburn;
float height;
float age;
float BMR;
float excess;
*pexcess=&excess;
char gender;
*pgender=&gender;
int main()
{
FILE *createfile=fopen("D:\\Desktop\\project.txt","a");
//Read the file to check if there is any number stored//
{
FILE *createfile=fopen("D:\\Desktop\\project.txt","r");
fscanf(createfile,"%f %f %f",&BMR,&idealweight,&curweight);
printf("%.2f",curweight);
printf("%.2f",BMR);
printf("%.2f",idealweight); //just to check the current weight//
}
//if there is no current weight stored,it will promt to store//
if(curweight==0)
{
FILE *createfile=fopen("D:\\Desktop\\project.txt","w");
printf("Welcome!\n");
printf("Please enter if male or female(M/F)");
scanf("%c",&gender);
*pgender=toupper(gender) ;
printf("Please enter your current weight in kg");
scanf("%f",&curweight);
printf("Please enter your current height in cm");
scanf("%f",&height);
printf("Please enter your age");
scanf("%f",&age);
printf("Please enter your desired weight");
scanf("%f",&idealweight);
fprintf(createfile,"%f\t",idealweight); //print ideal weight into file//
switch( gender )
{
case('M'):
printf("Calculating BMR for male:\n");
BMR=((66.5 + (13.75*curweight) + (5.003*height) - (6.755*age))*1.2);
break;
case('F'):
printf("Calculating BMR for female:\n");
BMR=((55.1 + (9.563 *curweight) + (1.850*height) - (4.676*age))*1.2);
break;
}//switch//
printf("\nIf you engage in no activity for the entire day is,your body will burn %.2f kcal(BMR).",BMR);
fprintf(createfile,"%f\t",BMR); //print BMR into file//
printf("\nPlease enter your how much calories you have consumed today");
scanf("%f",&daily);
excess=BMR-daily;//excess or lack
if(excess<0)
printf("You have consumed %f more then how much your body can burn.",excess);//to display positive number//
*pexcess=((1/7700)*excess);//change into kg
printf("You excess %f(kg).",excess); //test//
*pcurweight=curweight+excess; //must plusointo current weight(kg)//
printf("You current %f(kg.",curweight);//test//
else if(excess=0)
printf("Perfect!.",excess);
else if(excess>0)
{
printf("Its not healty to consume lesser than your BMR");
printf("You have consumed %f lesser than your BMR",excess);
* pexcess=((1/7700)*excess);//change into kg
printf("You excess%f(kg.",excess);//test//
*pcurweight=curweight-excess;//must minus ointo current weight(kg)//
printf("You current %f(kg.",curweight);
}
}//if there is not value in the file//
else
{
printf("Your current weight is %.2f",curweight);
printf("Please enter your how much calories you have consumed today");
scanf("%f",&daily);
*pcurweight=curweight + daily ;
printf("current %.2f",curweight);
fprintf(createfile,"\ncurrent weight is%.2f",curweight);
}
fclose(createfile);
return 0;
}