身高预测程序(C语言 已知父母身高预测孩子身高程序 求帮找错)

本文目录
C语言 已知父母身高预测孩子身高程序 求帮找错
#include《stdio.h》int main(){ int faheight,moheight; \\这里用int float a; char ***,sport,habit, ch; printf("Please input: Father’s height(space)Mother’s height(cm)\n"); scanf("%d %d",&faheight,&moheight); { printf("IF THE BABY IS A BOY?(y or n)\n"); while((ch=getchar())!=’\n’); \\所有getchar之前加一行这个 ***=getchar(); if(***==’y’)a=(faheight+moheight)*1.0*0.54; if(***==’n’)a=(faheight*0.923+moheight)/2; getchar(); } { printf("DOES HE/SHE LIKE SPORTS?(y or n)\n"); while((ch=getchar())!=’\n’); sport=getchar(); if(sport==’y’) a=a*1.02; if(sport==’n’) a=a*1.0; getchar(); } { printf("DOES HE/SHE H**E GOOD HABITS?(y or n)\n"); while((ch=getchar())!=’\n’); habit=getchar(); if(habit==’y’)a=a*1.015; if(habit==’n’)a=a; getchar(); } printf("Height=%.2f cm",a); return 0; }
编程 C语言
#include 《stdio.h》int main(){char ***;float faHeight, moHeight;char sports;char diet;float ChildHeight;/*孩子身高*/printf("请输入用户性别(F-女性,M-男性)、父母身高、是否喜爱体育运动(Y/N),是否有良好的饮食习惯(Y/N)");scanf("%c%f%f %c %c",&***, &faHeight, &moHeight, &sports, &diet);if (*** == ’F’ || *** == ’M’){if (*** == ’M’)ChildHeight = (faHeight + moHeight)*0.54;elseChildHeight = (faHeight*0.923 + moHeight)/2;if (sports == ’Y’ || sports == ’y’)ChildHeight =ChildHeight + 0.02*ChildHeight;if (diet == ’Y’ || diet == ’y’)ChildHeight += ChildHeight*0.015;printf("孩子身高预测为:%f", ChildHeight);}elseprintf("性别输入有误!程序退出!\n");return 0;}输入:M 170 160 Y Y 输出:184.49
java中用switch写身高预测
代码如下:
import java.util.Scanner;public class Test {public static void main(String args) {Scanner sc = new Scanner(System.in);System.out.print("请输入你的身高(三位数,输入0结束程序):");int i = sc.nextInt();while(i != 0){switch (i / 10) {case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9:case 10:case 11:case 12:System.out.println("这身高是个儿童.");break;case 13:case 14:case 15:case 16:System.out.println("这身高是个少年");break;case 17:case 18:System.out.println("这身高是个小伙子!");break;case 19:case 20:System.out.println("这是个小巨人");break;case 0:break;}i = sc.nextInt();}}}
如何用c#做一个身高预测程序
#include 《stdio.h》
/*
设faHeight为其父身高,moHeight为其母身高,身高预测公式为
男性成人时身高=(faHeight + moHeight)×0.54cm
女性成人时身高=(faHeight×0.923 + moHeight)/2cm
此外,如果喜爱体育锻炼,那么可增加身高2%;
如果有良好的卫生饮食习惯,那么可增加身高1.5%。
编程从键盘输入用户的性别(用字符型变量***存储,输入字符F表示女性,输入字符M表示男性)、
父母身高(用实型变量存储,faHeight为其父身高,moHeight为其母身高)、
是否喜爱体育锻炼(用字符型变量sports存储,输入字符Y表示喜爱,输入字符N表示不喜爱)、
是否有良好的饮食习惯等条件(用字符型变量diet存储,输入字符Y表示良好,输入字符N表示不好),
利用给定公式和身高预测方法对身高进行预测。
*/
void main()
{
double faHeight=0,moHeight = 0,yourHeight = 0;
char *** = 0,sports = 0,diet = 0;
printf("输入你父母的身高:");
scanf("%lf,%lf",&faHeight,&moHeight);
printf("输入你的性别(F代表女性,M代表男性):");
getchar();
scanf("%c",&***);
printf("是否喜爱体育锻炼?Y表示喜爱,N表示不喜爱");
getchar();
scanf("%c",&sports);
printf("是否有良好的饮食习惯?Y表示有,N表示没有");
getchar();
scanf("%c",&diet);
if(*** == ’M’)
yourHeight = (faHeight + moHeight) * 0.54;
else if(*** == ’F’)
yourHeight = (faHeight * 0.923 + moHeight)/2;
if(sports == ’Y’)
yourHeight = yourHeight * 1.02;
if(diet == ’Y’)
yourHeight = yourHeight * 1.015;
printf("你的身高是:%lf",yourHeight);
}
编写程序计算身高
#include 《stdio.h》int main(void){ float faHeight,moHeight,chHeight; printf("父亲的身高(cm):"); scanf("%f",&faHeight); printf("母亲的身高(cm):"); scanf("%f",&moHeight); printf("孩子的性别(M/F):"); getchar(); if(getchar() == ’M’){ chHeight = (faHeight + moHeight ) * 0.54; }else if(getchar() == ’F’){ chHeight = (faHeight * 0.923 + moHeight)/2; }else{ chHeight = 0; } getchar(); printf("是否喜爱体育锻炼(Y/N):"); if(getchar() == ’Y’){ chHeight *= 1.02; } getchar(); printf("是否有良好的卫生饮食习惯(Y/N):"); if(getchar() == ’Y’){ chHeight *= 1.015; } printf("预测的身高:%dcm\n",(int)(chHeight + 0.5)); return 0;}
C语言程序设计,身高的计算请各位帮忙看看我的程序,多谢了!
//顺序不对#include《stdio.h》int main(){ char ***,sports,diet; float faheight,moheight,height; printf("faheight="); //输入的单位以公斤计算 scanf("%f", &faheight); //输入的单位以公斤计算 printf("moheight="); scanf("%f", &moheight); printf("Male or Famale?Please input ’M’ or ’F’:"); scanf("%1s", &***); switch(***) { case’F’:height=(faheight+moheight)*0.54;break; case’M’:height=(faheight*0.923+moheight)/2;break; } printf("Do you like sports?please input’Y’ or ’N’:"); scanf("%1s", &sports); switch(sports) { case’Y’:height=height*(1.02);break; case’N’:height=height;break; } printf("Do you have good diet and habits?please input’Y’ or ’N’:"); scanf("%1s", &diet); //分析判断预测 switch(diet) { case’Y’:height=height*(1.015);break; case’N’:height=height;break; } printf("\nmy height is:%.3f",height); return 0;}

本文相关文章:
网红痞幼视频和照片(网红痞幼母爱泛滥,给干儿子洗澡、亲其脚丫,她对孩子有多宠爱)
2026年1月11日 13:40
陈好和他老公的结婚照(陈好是非常优秀的,为何网友见到她的孩子之后感叹孩子他爸的基因强大)
2026年1月7日 00:40
陈浩民老婆生五胎(陈浩民妻子坦言会生第五胎,是重男轻女还是真的喜欢孩子)
2025年11月3日 23:24
谢贤与张柏芝(谢贤不再沉默,公开与张柏芝三子关系,孩子是不是谢家的)
2025年11月3日 23:24
更多文章:
pdd中学在哪读的?昆明理工大学生命科学与技术学院的师资力量
2026年5月19日 09:10
吴费曼的性格奇怪(吴镇宇儿子自爆生病,12岁少年患社交恐惧,养废孩子就逼他外向)
2026年5月19日 07:40
温碧霞巅峰颜值照片(TVB古装美人,颜值巅峰期个个秒杀现在的古装美女,都有谁)
2026年5月19日 06:10
刘德华哭着道歉粉丝唱歌视频(刘德华薇娅在直播间合唱恭喜发财,这场面像不像过年)
2026年5月19日 05:40
小g是什么车(奔驰大G和小G是指什么奔驰大G为什么很少上高速)
2026年5月19日 05:30





























