C语言身高预测小程序(利用if、else、else if)(代码原创)
2021/12/19 14:49:44
本文主要是介绍C语言身高预测小程序(利用if、else、else if)(代码原创),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#include <stdio.h> #include <stdlib.h> int main(void) { char s; //孩子的性别 char sp; //是否喜欢体育运动 char d; //是否有良好的饮食习惯 float h; //我的身高 float fh; //父亲的身高 float mh; //母亲的身高 printf("Are you a boy(M) or a girl(F)?\n"); scanf(" %c",&s); if (!(s=='m' || s=='M' || s=='f' || s=='F')) printf("\nInput sex error!"); else { if(s=='m'||s=='M') { printf("Please input your father's height(cm):\n"); scanf(" %f",&fh); printf("Please input your mother's height(cm):\n"); scanf(" %f",&mh); h=(fh+mh)*0.54; printf("Do you like sports(Y/N)?\n"); scanf(" %c",&sp); if (!(sp=='y' || sp=='Y' || sp=='n' || sp=='N')) { printf("\nInput sports error!"); } else if (sp=='y' || sp=='Y') { h=1.02*h; } printf("Do you have a good habit of diet(Y/N)?\n"); scanf(" %c",&d); if (!(d=='y' || d=='Y' || d=='n' || d=='N')) { printf("Input diet error!\n"); } else if (d=='y' || d=='Y') { h=h*1.015; printf("Your future height will be %f(cm)\n",h); } } else { if(s=='f'||s=='F') printf("Please input your father's height(cm):\n"); scanf(" %f",&fh); printf("Please input your mother's height(cm):\n"); scanf(" %f",&mh); h=(fh*0.923+mh)/2; printf("Do you like sports(Y/N)?\n"); scanf(" %c",&sp); if (!(sp=='y' || sp=='Y' || sp=='n' || sp=='N')) { printf("\nInput sports error!"); } else if (sp=='y' || sp=='Y') { h=1.02*h; } printf("Do you have a good habit of diet(Y/N)?\n"); scanf(" %c",&d); if (!(d=='y' || d=='Y' || d=='n' || d=='N')) { printf("Input diet error!\n"); } else if (d=='y' || d=='Y') { h=h*1.015; printf("Your future height will be %f(cm)\n",h); } } } return 0; }
这篇关于C语言身高预测小程序(利用if、else、else if)(代码原创)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-30微信小程序的网络设置,及网络请求:wx.request(OBJECT)
- 2024-01-22基于taro搭建小程序多项目框架
- 2024-01-13小程序开发:在插件市场寻找步骤条组件并二开
- 2024-01-05钉钉小程序生态—企业机器人加互动卡片,改善用户体验的开始!
- 2023-12-29【UniApp】-uni-app-打包成小程序
- 2023-12-26性能翻倍!京东亿级体量小程序优化实践
- 2023-12-25小程序优化:第三方SDK过大解决方案
- 2023-11-26微信小程序文件预览和下载-文件系统
- 2023-11-2652天学习微信小程序计划No.2:注册小程序账号&安装开发者工具
- 2023-11-1952天学习微信小程序计划No.1:小程序简介