โปรเจคภาษาซี โปรเเกรมดูเเลสุขภาพ
เป็นตัวอย่างสำหรับผู้ที่สนใจ
ภายในโปรเเกรมจะประกอบไปด้วย
การคำนวณ bmi
การคำนวณ bmr
การคำนวณ tdee
การคำนวน ปริมาณโปรตีนที่จำเป็นต่อวัน
การคำนวณ ปริมาณไขมันในร่างกาย
เป็นต้น
ส่วนของCODE
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
typedef struct information{
char first[20];
char last[20];
char email[30];
char gender[6];
int date[10];
int phone[12];
float BMI;
float BMR;
float TDEE;
float PROTEIN;
float PROTEIN1;
int age;
float height;
float weight;
int gender1;
float bodyweight,wrist,waist,hip,forearm;
float A1,A2,A3,A4,A5,B,bodyfat,bodyfatparcentage;
}info;
typedef struct Account{
char username[20],password[20];
info form;
}User;
User user[20];
void printLine(){
printf("***************************************************************************************************************************************************************************************************\n");
}
void time();
void menu();
void home();
void Register();
void login();
main(){
system("color 8F");
home();
getch();
}
void home(){
int home;
printf("\t\t\t ____________________________________________\n");
printf("\t\t\t***************************| WELCOME TO PROGRAM |******************************\n");
printf("\t\t\t***************************| HEALTH CARE |******************************\n");
printf("\t\t\t** |____________________________________________| **\n");
printf("\t\t\t** **\n");
printf("\t\t\t** **\n");
printf("\t\t\t** __________________________________________ **\n");
printf("\t\t\t** | | **\n");
printf("\t\t\t** |-------------> 1. Register <-------------| **\n");
printf("\t\t\t** | | **\n");
printf("\t\t\t** |__________________________________________| **\n");
printf("\t\t\t** __________________________________________ **\n");
printf("\t\t\t** | | **\n");
printf("\t\t\t** |--------------> 2. Login <--------------| **\n");
printf("\t\t\t** | | **\n");
printf("\t\t\t** |__________________________________________| **\n");
printf("\t\t\t** __________________________________________ **\n");
printf("\t\t\t** | | **\n");
printf("\t\t\t** |--------------> 3. Exit <--------------| **\n");
printf("\t\t\t** | | **\n");
printf("\t\t\t** |__________________________________________| **\n");
printf("\t\t\t** **\n");
printf("\t\t\t** **\n");
printf("\t\t\t*******************************************************************************************************\n");
printf("\t\t\t*******************************************************************************************************\n\n\n");
printf("Please select your choice :");
scanf("%d",&home);
printf("\n\n");
printf("______________________________________________________________");time();
switch (home){
case 1 :Register() ;
break;
case 2 :login();
break;
case 3 :printf("**thank you and see you again**\n");
break;
}
getch();
}
void Register(){
User a;
FILE *user,*pass;
user=fopen("C:\\Users\\ASUS\\Desktop\\compro\\user","w");
pass=fopen("C:\\Users\\ASUS\\Desktop\\compro\\pass","w");
printf("\t============================================\n");
printf("\t\t<>----Register----<>\n\n");
printf("\tEnter your username: ");
scanf("%s", &a.username);
fprintf(user,"%s",a.username);
fclose(user);
printf("\tEnter your password: ");
scanf("%s",&a.password);
fprintf(pass,"%s",a.password);
fclose(pass);
printf("\t============================================\n");
printf("\t\t<>Register successful!!<>\n");
printf("______________________________________________________________");time();
home();
}
void time (void){
time_t lt;
int lenght;
lt = time(NULL);
printf(ctime(<));
}
void login(){
FILE *user,*pass;
char user1[20],username[20],pw[20],password[20];
user=fopen("C:\\Users\\ASUS\\Desktop\\compro\\user","r");
pass=fopen("C:\\Users\\ASUS\\Desktop\\compro\\pass","r");
fscanf(user,"%s",username);
printf("\nLogin Menu!!\n");
printf("\tEnter your username : ");
scanf("%s",user1);
fclose(user);
while (strcmp(username,user1)!=0){
printf("Username wrong!!!\n");
printf("\tPlease enter your username again : ");
scanf("%s",user1);
}
fscanf(pass,"%s",password);
fclose(pass);
printf("\tEnter your password : ");
scanf("%s",pw);
while (strcmp(password,pw)!=0){
printf("Password wrong!!!\n");
printf("\tPlease enter your password again : ");
scanf("%s",pw);
}
menu();
}
void menu(){
int menu=0,choice=0 ;
info a;
FILE*profile;
profile=fopen("C:\\Users\\ASUS\\Desktop\\compro\\profile","w");
while(menu != 11){
printLine();
printf("\t\t\t\t=======================================================================\n");
printf("\t\t\t\t||____________________ Excercises Calculator__________________________||\n");
printf("\t\t\t\t||1. PROFILE ||\n");
printf("\t\t\t\t||2. BMI calculate ||\n");
printf("\t\t\t\t||3. BMR calculate ||\n");
printf("\t\t\t\t||4. TDEE calculate ||\n");
printf("\t\t\t\t||5. Essential protein quantity calculate ||\n");
printf("\t\t\t\t||6. Body fat calculate ||\n");
printf("\t\t\t\t||7. Display statistic ||\n");
printf("\t\t\t\t||8. Lose weight suggestions ||\n");
printf("\t\t\t\t||9. How to check the amount of calories on food and beverage labels ||\n");
printf("\t\t\t\t||10.Table of food versus calories ||\n");
printf("\t\t\t\t||11. Exit ||\n");
printf("\t\t\t\t||====================================================================||\n");
printf("Enter your choice : ");
scanf("%d",&menu);
switch(menu){
case 1 :
printf("\t\t|--PROFILE--|\n");
printf("\tFirst name: ");
scanf("%s",&a.first);
printf("\tLast name: ");
scanf("%s",a.last);
printf("\tEmail address: ");
scanf("%s",&a.email);
printf("\tDate of Birth <day/month/year>: ");
scanf("%s",&a.date);
printf("\tPhone number: ");
scanf("%d",&a.phone);
break;
case 2 :
printf("\tEnter height <m> : ");
scanf("%f",&a.height);
printf("\tEnter weight <kg> : ");
scanf("%f",&a.weight);
a.BMI = a.weight / pow(a.height,2);
printf("\n\t\tYour BMI is %.2f kg/m^2\n" , a.BMI);
if(a.BMI < 16){
printf("\tYou\'re Severe Thinness\n");
}
else if(a.BMI >= 16 && a.BMI < 17){
printf("\tYou\'re Moderate Thinness\n");
}
else if(a.BMI >= 17 && a.BMI < 18.5){
printf("\tYou\'re Mild Thinness\n");
}
else if(a.BMI >= 18.5 && a.BMI < 25){
printf("\tYou\'re Normal\n");
}
else if(a.BMI >= 25 && a.BMI < 30){
printf("\tYou\'re Overweight\n");
}
else if(a.BMI >= 30 && a.BMI < 35){
printf("\tYou\'re Obese Class I\n");
}
else if(a.BMI >= 35 && a.BMI < 40){
printf("\tYou\'re Obese Class II\n");
}
else{
printf("\tYou\'re Obese Class III\n");
}
break;
case 3 :
printf("\tEnter your gender <Male / Female> : ");
scanf("%s",&a.gender);
printf("\tEnter height <m> : ");
scanf("%f",&a.height);
printf("\tEnter weight <kg> : ");
scanf("%f",&a.weight);
printf("\tEnter age : ");
scanf("%d",&a.age);
if(strcmp(a.gender,"Male") == 0){
a.BMR = (10 * a.weight) + (6.25 * (a.height*100)) - (5 * a.age) + 5;
}
else if(strcmp(a.gender,"Female") == 0){
a.BMR = (10 * a.weight) + (6.25 * (a.height*100)) - (5 * a.age) - 161;
}
printf("\n\t\tYour BMR is %.2f kcal\n",a.BMR);
break;
case 4 :
printf("^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\nYour daily routine\n");
printf("1. Sedentary\n");
printf("2. Lightly Active\n");
printf("3. Moderately Active\n");
printf("4. Very Active\n");
printf("5. Extremely Active\n");
printf("\tEnter your choice : ");
scanf("%d",&choice);
printf("^^^^^^^^^^^^^^^^^^^^^^^^^\n");
switch(choice){
case 1 : a.TDEE = a.BMR * 1.2; break;
case 2 : a.TDEE = a.BMR * 1.375; break;
case 3 : a.TDEE = a.BMR * 1.55; break;
case 4 : a.TDEE = a.BMR * 1.725; break;
case 5 : a.TDEE = a.BMR * 1.9; break;
}
printf("\n\t\tYour TDEE is %.2f kcal\n" , a.TDEE);
break;
case 5 :
printLine();
printf("\tEnter weight <kg> : ");
scanf("%f",&a.weight);
a.PROTEIN = a.weight*0.8;
printf("\n\t\tThe amount of protein that the body needs is %.2f grams/day \n\n",a.PROTEIN);
a.PROTEIN1 = a.PROTEIN*4;
printf("\n\t\tEnergy from protein is %.2f kcal \n\n",a.PROTEIN1);
printf("\tSuggestion \n");
printf("\tFor pregnant women \n");
printf("\tThe amount of protein needed by the body is 75 grams per day. \n ");
printf("\tFor exercise or athletes \n");
printf("\tThe amount of protein needed by the body is 100 grams per day. \n");
break;
case 7 :
printLine();
printf("\t************************************************\n");
printf("\tFirst name : %s\n" , a.first);
printf("\tLast name : %s\n" , a.last);
printf("\tEmail address : %s\n" , a.email);
printf("\tDate of Birth : %s\n" , a.date);
printf("\tPhone number: %d\n" , a.phone);
printf("\tHeight <m> : %.2f\n" , a.height);
printf("\tWeight <kg> : %.2f\n" , a.weight);
printf("\tAge <years old> : %d\n" , a.age);
printf("\tGender : %s\n" , a.gender);
printf("\tBMI <kg/m^2> : %.2f\n" , a.BMI);
printf("\tBMR <kcal> : %.2f\n" , a.BMR);
printf("\tTDEE <kcal>: %.2f\n" , a.TDEE);
printf("\tThe amount of protein that the body needs <grams> : %.2f\n" , a.PROTEIN);
printf("Body Fat is equal to : %.2f \n",a.bodyfat);
printf("Body Fat percentage is equal to : %.2f \n",a.bodyfatparcentage);
printf("\t************************************************\n");
fprintf(profile,"\tFirst name : %s\n" , a.first);
fprintf(profile,"\tLast name : %s\n" , a.last);
fprintf(profile,"\tEmail address : %s\n" , a.email);
fprintf(profile,"\tDate of Birth : %s\n" , a.date);
fprintf(profile,"\tPhone number: %d\n" , a.phone);
fprintf(profile,"\tHeight <m> : %.2f\n" , a.height);
fprintf(profile,"\tWeight <kg> : %.2f\n" , a.weight);
fprintf(profile,"\tAge <years old> : %d\n" , a.age);
fprintf(profile,"\tGender : %s\n" , a.gender);
fprintf(profile,"\tBMI <kg/m^2> : %.2f\n" , a.BMI);
fprintf(profile,"\tBMR <kcal> : %.2f\n" , a.BMR);
fprintf(profile,"\tTDEE <kcal>: %.2f\n" , a.TDEE);
fprintf(profile,"\tThe amount of protein that the body needs <grams> : %.2f\n" , a.PROTEIN);
fprintf(profile,"Body Fat is equal to : %.2f",a.bodyfat);
fprintf(profile,"Body Fat percentage is equal to : %.2f",a.bodyfatparcentage);
fclose(profile);
break;
case 8 :
printLine();
printf("\t|-----------Lose weight suggestions-----------|\n");
printf("\t|<1> Eat a high-protein breakfast |\n");
printf("\t|<2> Avoid sugary drinks and fruit juice |\n");
printf("\t|<3> Drink water a half hour before meals |\n");
printf("\t|<4> Choose weight loss-friendly foods |\n");
printf("\t|<5> Eat soluble fiber |\n");
printf("\t|<6> Drink coffee or tea |\n");
printf("\t|<7> Eat mostly whole, unprocessed foods |\n");
printf("\t|<8> Eat your food slowly |\n");
printf("\t|<9> Weigh yourself every day |\n");
printf("\t|<10> Get a good night's sleep, every night |\n");
printf("\t|---------------------------------------------|\n");
break;
case 9 :
printLine();
printf("1. Total fat\n");
printf("2. Saturated fat\n");
printf("3. Sugar\n");
printf("\tEnter your choice : ");
scanf("%d",&choice);
switch(choice){
case 1 : printf("\t >>> High dose: more than 17.5 grams, fat content 100 grams\n");
printf("\t >>> Low amount: 3 grams of fat content 100 grams or less\n");
break;
case 2 : printf("\t >>> High dose: more than 5 grams of saturated fat content of 100 grams\n");
printf("\t >>> Minimum volume: 1.5 grams of shipping volume 100 grams or less\n");
break;
case 3 : printf("\t >>> High dosage: more than 22.5 grams of total sugar content 100 grams\n");
printf("\t >>> Low amount: 5 grams of total sugar content 100 grams or less\n");
break;
}
break;
case 10 :
printLine();
printf("1. Meat\n");
printf("2. Starchy food\n");
printf("3. Fruit\n");
printf("4. Dessert\n");
printf("5. Drinks\n");
printf("\tEnter your choice : ");
scanf("%d",&choice);
switch(choice){
case 1 :
printf(" ___________________________________________________________\n");
printf("| Meat | Amount(grams) | Calorie(cal) |\n");
printf("|____________________|___________________|__________________|\n");
printf("|1. Pork | 15 | 35 |\n");
printf("|2. Pork tenderloin | 15 | 26 |\n");
printf("|3. Chicken | 15 | 35 |\n");
printf("|4. Chicken breast | 15 | 26 |\n");
printf("|5. Shrimp | 15 | 26 |\n");
printf("|6. Crab meat | 15 | 26 |\n");
printf("|7. Beef | 15 | 26 |\n");
printf("|8. Duck meat | 15 | 35 |\n");
printf("|____________________|___________________|__________________|\n");
break;
case 2 :
printf(" ___________________________________________________________\n");
printf("| Starchy food | Amount(grams) | Calorie(cal) |\n");
printf("|____________________|___________________|__________________|\n");
printf("|1. Instant noodles | 20 | 80 |\n");
printf("|2. Bread | 30 | 80 |\n");
printf("|3. Sticky rice | 35 | 80 |\n");
printf("|4. Cooked rice | 60 | 80 |\n");
printf("|5. Rice Noodles | 72 | 80 |\n");
printf("|6. macaroni | 80 | 80 |\n");
printf("|7. noodle | 54 | 80 |\n");
printf("|____________________|___________________|__________________|\n");
break;
case 3 :
printf(" ___________________________________________________________\n");
printf("| Fruit | Amount(grams) | Calorie(cal) |\n");
printf("|____________________|___________________|__________________|\n");
printf("|1. Banana | 40 | 67 |\n");
printf("|2. Durian | 40 | 67 |\n");
printf("|3. Custard apple | 60 | 67 |\n");
printf("|4. Jackfruit | 60 | 67 |\n");
printf("|5. Mango | 75 | 67 |\n");
printf("|6. Rambutan | 76 | 67 |\n");
printf("|7. Apple | 80 | 67 |\n");
printf("|8. Sapodilla | 80 | 67 |\n");
printf("|9. Longan | 80 | 67 |\n");
printf("|10. Mangosteen | 80 | 67 |\n");
printf("|11. Dragonfruit | 100 | 67 |\n");
printf("|12. lychee | 100 | 67 |\n");
printf("|13. Grapefruit | 100 | 67 |\n");
printf("|14. Pine apple | 108 | 67 |\n");
printf("|15. Grape | 110 | 67 |\n");
printf("|16. Guava | 128 | 67 |\n");
printf("|17. Rose apple | 128 | 67 |\n");
printf("|18. Watermelon | 275 | 67 |\n");
printf("|____________________|___________________|__________________|\n");
break;
case 4 :
printf(" ___________________________________________________________\n");
printf("| Dessert | Amount(grams) | Calorie(cal) |\n");
printf("|____________________|___________________|__________________|\n");
printf("|1. Donuts | 1 | 280 |\n");
printf("|2. Pineapple pie | 1 | 480 |\n");
printf("|3. Cheesecake | 1 | 340 |\n");
printf("|4. Cookies | 2 | 240 |\n");
printf("|5. Brownies | 1 | 350 |\n");
printf("|6. Banana Cake | 1 | 350 |\n");
printf("|7. Eclair | 1 | 200 |\n");
printf("|8. ice cream | 1 | 330 |\n");
printf("|____________________|___________________|__________________|\n");
break;
case 5 :
printf(" ___________________________________________________________\n");
printf("| Drinks | Amount | Calorie(cal) |\n");
printf("|____________________|_(a glass of drink)|__________________|\n");
printf("|1. Latte | 1 | 288 |\n");
printf("|2. Milk | 1 | 125 |\n");
printf("|3. Beer | 1 | 148 |\n");
printf("|4. Chocolate | 1 | 120 |\n");
printf("|5. Vodka | 1 | 120 |\n");
printf("|6. Whiskey | 1 | 140 |\n");
printf("|7. Mocha | 1 | 80 |\n");
printf("|8. Espresso | 1 | 0 |\n");
printf("|____________________|___________________|__________________|\n");
break;
}
break;
case 6 :
printf("\t\tThis program is to calculate the body fat of a person \n");
printf("If you are woman than press 1 . If you are man than press 2 \n");
scanf("%d",&a.gender1);
switch(a.gender1){
case 1 :
printf("Enter your body weight :");
scanf("%f",&a.bodyweight);
a.A1=(a.bodyweight*0.732)+8.987;
printf("Enter your wrist measurement :");
scanf("%f",a.wrist);
a.A2=a.wrist/3.140;
printf("Enter your waist measurement :");
scanf("%f",&a.waist);
a.A3=(a.waist)*0.157;
printf("Enter your hip measurement :");
scanf("%f",&a.hip);
a.A4=a.hip*0.249;
printf("Enter your forearm measurement ");
scanf("%f",&a.forearm);
a.A5=a.forearm*0.434;
a.B=a.A1+a.A2-a.A3-a.A4+a.A5;
a.bodyfat=a.B-a.bodyweight;
printf("Body Fat is equal to = %.2f",a.bodyfat);
a.bodyfatparcentage=(a.bodyfat*100)/a.bodyweight;
printf("Body Fat percentage is equal to = %.2f",a.bodyfatparcentage);
break;
case 2 :
printf("Enter your body weight ");
scanf("%f",&a.bodyweight);
a.A1=(a.bodyweight*1.082)+94.42;
printf("Enter your wrist measurement :");
scanf("%f",&a.wrist);
a.A2=a.wrist*4.15;
a.B=a.A1-a.A2;
a.bodyfat=a.B-a.bodyweight;
printf("Body Fat is equal to = %.2f ",a.bodyfat);
a.bodyfatparcentage=(a.bodyfat*100)/a.bodyweight;
printf("Body Fat percentage is equal to = %.2f ",a.bodyfatparcentage);
break;
}
}
}
}
ความคิดเห็น
แสดงความคิดเห็น