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-11-22微信小程序的接口信息py可以抓到吗?-icode9专业技术文章分享
- 2024-11-22怎样解析出微信小程序二维码带的参数?-icode9专业技术文章分享
- 2024-11-22微信小程序二维码怎样解析成链接?-icode9专业技术文章分享
- 2024-11-22微信小程序接口地址的域名需要怎么设置?-icode9专业技术文章分享
- 2024-11-22微信小程序的业务域名有什么作用-icode9专业技术文章分享
- 2024-11-22微信小程序 image有类似html5的onload吗?-icode9专业技术文章分享
- 2024-11-22微信小程序中怎么实现文本内容超出行数后显示省略号?-icode9专业技术文章分享
- 2024-11-22微信小程序怎么实现分享样式定制和图片定制功能?-icode9专业技术文章分享
- 2024-11-20微信小程序全栈教程:从零开始的全攻略
- 2024-11-19微信小程序全栈学习:从零开始的完整指南