身高预测编程(JavaScript 利用 if 和 提示窗口 计算身高)

本文目录
JavaScript 利用 if 和 提示窗口 计算身高
《!doctype html》《html lang="en"》 《head》 《meta charset="UTF-8"》 《meta name="Generator" content="EditPlus:registered:"》 《meta name="Author" content=""》 《meta name="Keywords" content=""》 《meta name="Description" content=""》 《title》Document《/title》 《script type="text/javascript"》function predictHeight() {var *** = prompt(’请输入性别(F:女, M:男):’, ’’);if (*** !== ’F’ && *** != ’M’) {alert(’性别输入错误’);return;}var faHeight = prompt(’请输入父亲身高:’, ’’);if (!//.test(faHeight)) {alert(’身高输入错误’);return;} else {faHeight = parseInt(faHeight);}var moHeight = prompt(’请输入母亲身高:’, ’’);if (!//.test(moHeight)) {alert(’身高输入错误’);return;} else {moHeight = parseInt(moHeight);}var sports = prompt(’是否喜爱体育锻炼(Y/N)?’, ’’);if (sports.toUpperCase() !== ’Y’ && sports.toUpperCase() !== ’N’) {alert(’只能输入Y/N’);return;}var diet = prompt(’是否有良好的饮食习惯(Y/N)?’, ’’);if (diet.toUpperCase() !== ’Y’ && diet.toUpperCase() !== ’N’) {alert(’只能输入Y/N’);return;}var height;if (*** === ’M’) {height = (faHeight + moHeight) * 0.54;} else {height = (faHeight * 0.923 + moHeight) / 2;}if (sports === ’Y’) {height = height * 1.02;}if (diet === ’Y’) {height = height * 1.015;}alert(’身高为’ + height + ’cm’);}predictHeight(); 《/script》 《/head》 《body》 《/body》《/html》
如何通过编程预知自己的身高
#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);
}
C语言编程问题
#include 《iostream》using namespace std;class Cheight{public: void getPHeight();//获得父母的身高 void getBasicHeight();//获取基本的身高 void getSports();//是否锻炼 void getDiet();//获取饮食习惯 void getFinalHeight();//获取身高private: //int n;//数据个数 //float child; float faHeight,moHeight,basHeight,finalHeight; char ***,sports,diet;};void Cheight::getPHeight(){ cout 《《 "请输入父亲的身高:"; cin 》》 faHeight; cout 《《 "请输入母亲的身高:"; cin 》》 moHeight;}void Cheight::getBasicHeight(){ cout 《《 "请输入性别(男:m,女:f):"; cin 》》 ***; if(*** == ’m’||*** == ’M’) { basHeight = (faHeight + moHeight) * 0.54; } else if(*** == ’f’ || *** == ’F’) { basHeight = (faHeight * 0.923 + moHeight) / 2; } else cout 《《 "ERROR!";}void Cheight::getSports(){ cout 《《 "是否喜欢运动(是:y,否:n):"; cin 》》 sports; if(sports == ’y’ || sports == ’Y’) { basHeight = basHeight * (1 + 0.02); }}void Cheight::getDiet(){ cout 《《 "是否有好的饮食习惯(是:y):"; cin 》》 diet; if(diet == ’y’ || diet == ’Y’) { basHeight = basHeight * (1 + 0.015); }}void Cheight::getFinalHeight(){ finalHeight = basHeight; cout 《《 "您的身高是:" 《《 finalHeight 《《 "cm";}int main(){ Cheight testHeight; testHeight.getPHeight(); testHeight.getBasicHeight(); testHeight.getSports(); testHeight.getDiet(); testHeight.getFinalHeight(); return 0;}写了一个只测试当个人的,如果测试一组人,请设置为数组。这个请楼主自己思考!

本文相关文章:
2021年男生正常身高体重表(男女生平均身高20212021成年男标准身高表)
2026年3月15日 09:20
更多文章:
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
































