Système de résultat BP
#include <stdio.h>
#include <stdlib.h>
int getuserinput();
int calcaverage();
int clasifycondition();
int gethighest();
float bp[3][5];
char stdname[5][10];
float finalavg[5];
char condclass[5][20];
float highestavg;
char namecpy[5][10];
int main()
{
getuserinput();
calcaverage();
clasifycondition();
gethighest();
printf("\nName Mon Tues Wed Avg Condition");
printf("\n%s %.2f %.2f %.2f %.2f %s",namecpy[0],bp[0][0],bp[0][1],bp[0][2],finalavg[0],condclass[0]);
printf("\n%s %.2f %.2f %.2f %.2f %s",namecpy[1],bp[1][0],bp[1][1],bp[1][2],finalavg[1],condclass[1]);
printf("\n%s %.2f %.2f %.2f %.2f %s",namecpy[2],bp[2][0],bp[2][1],bp[2][2],finalavg[2],condclass[2]);
printf("\n%s %.2f %.2f %.2f %.2f %s",namecpy[3],bp[3][0],bp[3][1],bp[3][2],finalavg[3],condclass[3]);
printf("\n%s %.2f %.2f %.2f %.2f %s",namecpy[4],bp[4][0],bp[4][1],bp[4][2],finalavg[4],condclass[4]);
printf("\nHighest Avg: %.2fmm HG\n\n",highestavg);
return 0;
}
int getuserinput()
{
int daycounter=1,stdcounter=1;
printf("========================================================================\n");
printf("======PUSAT KESIHATAN UNIVERSITI (PKU) UNIVERSITI MALAYSIA PAHANG=======\n");
printf("========================================================================\n");
for(int stdnum=0;stdnum<5;stdnum++)
{
printf("\nEnter student name %d: ",stdcounter);
scanf("%s",&stdname[stdnum]);
stdcounter=stdcounter+1;
strcpy(namecpy[stdnum],stdname[stdnum]);
for (int x=0;x<3;x++)
{
printf("BP reading for day %d: ",daycounter);
scanf("%f",&bp[stdnum][x]);
daycounter=daycounter+1;
}
daycounter=1;
}
return bp;
}
int calcaverage()
{
float avg;
float sum;
for(int x=0;x<5;x++)
{
avg=0;
sum=0;
for(int y=0;y<3;y++)
{
sum=sum+bp[x][y];
}
avg=sum/3;
finalavg[x]=avg;
//printf("\nThe %d average is%.2f",x,finalavg[x]);
}
}
int clasifycondition()
{
char class1[]="Pre-hypertension";
char class2[]="Hypertension Stage 1";
char class3[]="Hypertension Stage 2";
char class4[]="Hypertensive Crisis";
for(int x=0;x<5;x++)
{
if(finalavg[x]<120)
{
strcpy(condclass[x],"Normal");
}
else if(finalavg[x]>=120&&finalavg[x]<=139.99)
{
strcpy(condclass[x],class1);
}
else if(finalavg[x]>=140&&finalavg[x]<=159.99)
{
strcpy(condclass[x],class2);
}
else if(finalavg[x]>=160&&finalavg[x]<=179.99)
{
strcpy(condclass[x],class3);
}
else if(finalavg[x]>=180)
{
strcpy(condclass[x],class4);
}
}
}
int gethighest()
{
for(int x=0;x<4;x++)
{
if(finalavg[x]>finalavg[x+1])
{
highestavg=finalavg[x];
}
else
{
highestavg=finalavg[x+1];
}
}
}
Important Ibis