โค๊ดนี้มันเป็น พวกคำนวณค่าBMI(ดัชนีมวลกาย)ตามที่เราป้อนข้อมูลลงไปอ่ะครับ คืออยากจะทราบหลักการทำงานของแต่ละคำสั่ง ช่วยหน่อยนะครับ ขอบคุณล่วงหน้าครับ
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char password[10],user[10],ch;
int i=0 ;
printf("\n Enter your User Name : ");
scanf("%s",user);
printf("\n Enter your Password : ");
do{
ch=getch();
password[i++]=ch;
putchar('*');
}while(ch!=13);
password[--i]='\0';
if(strcmp(password,"000000")==0 && strcmp(user,"CC")==0)
{
printf("\n Welcome to system\n");
float findBMI(float height,float weight)
{
height/=100;
return weight/(height*height);
}
float findNormalWeight(float height)
{
height/=100;
float normalBMI=21;
return normalBMI*height*height;
}
{
float h,w,bmi;
printf("\n\n\nFind BMI.\n");
printf(" Please enter Height(cm) : ");
scanf("%f",&h);
printf(" Plesae enter Weight(kg) : ");
scanf("%f",&w);
bmi=findBMI(h,w);
printf("BMI score is : %.2f\n\n",bmi);
if(bmi>=40)
printf(" You are very Fat\nYou should lose your weight about %.0f KG",w-findNormalWeight(h));
else if(bmi>=35)
printf(" You are Fat lv2\nYou should lose your weight about %.0f KG",w-findNormalWeight(h));
else if(bmi>=28.5)
printf(" You are Fat lv1\nYou should lose your weight about %.0f KG",w-findNormalWeight(h));
else if(bmi>=23.5)
printf(" You are tiny fat\nYou should lose your weight about %.0f KG",w-findNormalWeight(h));
else if(bmi>=18.5)
printf(" You are normal");
else if(bmi>=0)
printf(" You are thin");
else
printf("Error Please any key to exit program...");
}
getch();
}
}
ช่วยอธิบายการทำงานของโค๊ด นี้ด้วยครับ(ภาษาC++)
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char password[10],user[10],ch;
int i=0 ;
printf("\n Enter your User Name : ");
scanf("%s",user);
printf("\n Enter your Password : ");
do{
ch=getch();
password[i++]=ch;
putchar('*');
}while(ch!=13);
password[--i]='\0';
if(strcmp(password,"000000")==0 && strcmp(user,"CC")==0)
{
printf("\n Welcome to system\n");
float findBMI(float height,float weight)
{
height/=100;
return weight/(height*height);
}
float findNormalWeight(float height)
{
height/=100;
float normalBMI=21;
return normalBMI*height*height;
}
{
float h,w,bmi;
printf("\n\n\nFind BMI.\n");
printf(" Please enter Height(cm) : ");
scanf("%f",&h);
printf(" Plesae enter Weight(kg) : ");
scanf("%f",&w);
bmi=findBMI(h,w);
printf("BMI score is : %.2f\n\n",bmi);
if(bmi>=40)
printf(" You are very Fat\nYou should lose your weight about %.0f KG",w-findNormalWeight(h));
else if(bmi>=35)
printf(" You are Fat lv2\nYou should lose your weight about %.0f KG",w-findNormalWeight(h));
else if(bmi>=28.5)
printf(" You are Fat lv1\nYou should lose your weight about %.0f KG",w-findNormalWeight(h));
else if(bmi>=23.5)
printf(" You are tiny fat\nYou should lose your weight about %.0f KG",w-findNormalWeight(h));
else if(bmi>=18.5)
printf(" You are normal");
else if(bmi>=0)
printf(" You are thin");
else
printf("Error Please any key to exit program...");
}
getch();
}
}