m0_59308733 2021-06-15 08:50 采纳率: 25%
浏览 33
已采纳

提问关于c语言编程的题目

 

  • 写回答

5条回答 默认 最新

  • CSDN专家-sinJack 2021-06-15 08:57
    关注

    如有帮助,望采纳,点击我回答右上角【采纳】按钮。

    #include <stdio.h>
    #include<stdlib.h>
    #include<string.h>
    int main() {
        int result = 0;
        float faHeight, moHeight, manHeight, womanHeight;    //变量的声明,父母身高,用户男女身高
        char sex, sports, diet;                              //性别,运动,饮食习惯
        printf("Please enter your gender:F or M\n");
        scanf("%c", &sex);           //输入性别                //输入用户性别
        while (sex != 'M' && sex != 'F') {                   //都性别输入进行判断,是否符合格式
            printf("输入错误,请重新输入:\n");
            fflush(stdin);                                    //不符合,清楚缓存中的数据
            scanf("%c", &sex);                                //重新输入
        }
        fflush(stdin);                                        //清楚缓存中的数据
        printf("Please enter the height of the father and mother\n");
        result = scanf("%f %f", &faHeight, &moHeight);        //输入父母的身高
        while (result != 2) {                                 //根据scanf()的返回值判断输入是否正确
                printf("输入错误请重新输入:\n");
                fflush(stdin);
                result = scanf("%f %f", &faHeight, &moHeight);
     
        }
            fflush(stdin);
            printf("Do you like physical exercise:Y or N\n");
            scanf("%c", &sports);                      //是否喜欢运动
            while (sports != 'Y' && sports != 'N') {      //格式判断
                printf("输入错误,请重新输入:\n");
                fflush(stdin);
                scanf("%c", &sports);
            }
            fflush(stdin);
            printf("Do you have good eating habits:Y or N\n");
            scanf("%c", &diet);                        //是否有良好的饮食习惯
            while (diet != 'Y' && diet != 'N') {        //格式判断
                printf("输入错误,请重新输入:\n");
                fflush(stdin);
                scanf("%c", &diet);
            }
            fflush(stdin);
            manHeight = (faHeight + moHeight) * (0.54);       //计算男性身高
            womanHeight = (faHeight * (0.923) + moHeight) / 2;  //计算女性身高
            if (sports == 'Y') {                                //是否喜欢运动
                manHeight = manHeight * (1 + 0.02);
                womanHeight = womanHeight * (1 + 0.02);
                if (diet == 'Y') {                             //是否有良好的饮食习惯
                    manHeight = manHeight * (1 + 0.015);
                    womanHeight = womanHeight * (1 + 0.015);
                }
            }
            if (sex == 'F') {                               //输入判断时男性或者女性用户
                printf("Your height is %f cm", manHeight);
            } else {
                printf("Your height is %f cm", womanHeight);
            }
            return 0;
        }
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度