ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

C语言身高预测小程序(利用if、else、else if)(代码原创)

2021-12-19 14:32:20  阅读:706  来源: 互联网

标签:cm scanf sp C语言 height else printf 身高


 

#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;
}

 

 

标签:cm,scanf,sp,C语言,height,else,printf,身高
来源: https://blog.csdn.net/qq_63108921/article/details/122022995

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有