想知道如何进行第二个问题如何增加对话功能,提示是否继续进行预测就行,不必回答第一个问题。
1条回答 默认 最新
- 5年helloword开发经验 2022-01-26 16:48关注
/*********仅供参考***************/ #include <stdio.h> #include <string.h> #include <stdlib.h> #define MAN_HEIGHT(faheight,moheight,k1,k2) ((faheight+moheight)*0.54*(1+k1)*(1+k2)) #define WONMAN_HEIGHT(faheight,moheight,k1,k2) ((faheight*0.923+moheight)/2*(1+k1)*(1+k2)) float good_movement() { printf("Do you like sports?(Y or N)\n"); char ok=getchar(); getchar(); if(ok=='Y') return 0.02; else if(ok=='N') return 0.0; else return -1; } float good_diet() { printf("Have a good diet?(Y or N)\n"); char ok=getchar(); getchar(); if(ok=='Y') return 0.015; else if(ok=='N') return 0.0; else return -1; } int user_height() { char gender[10]={0}; float k1,k2; int faheight,moheight; printf("Enter the gender(MAN or WONMAN):\n"); scanf("%s",gender); getchar(); if(!strcmp(gender,"MAN")) { printf("Enter the height of father and mother(father,mother):"); scanf("%d,%d",&faheight,&moheight); getchar(); k1=good_movement(); k2=good_diet(); if(k1==-1||k2==-1) return -1; return MAN_HEIGHT(faheight,moheight,k1,k2); } else if(!strcmp(gender,"WOMAN")) { printf("Enter the height of father and mother(father,mother):"); scanf("%d,%d",&faheight,&moheight); getchar(); k1=good_movement(); k2=good_diet(); if(k1==-1||k2==-1) return -1; return WONMAN_HEIGHT(faheight,moheight,k1,k2); } else return -1; } int main() { char ok; int predict_height; L: system("cls"); do{ predict_height=user_height(); if(predict_height==-1) { printf("Invalid format\n"); printf("Press enter to continue\n"); getchar(); goto L; } printf("predict_height:%d\n",predict_height); printf("Whether or not to continue(Y or y)?\n"); printf("Other keys exit.\n"); ok=getchar(); getchar(); }while(ok=='Y'||ok=='y'); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
- ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
- ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
- ¥20 神经网络Sequential name=sequential, built=False
- ¥16 Qphython 用xlrd读取excel报错
- ¥15 单片机学习顺序问题!!
- ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
- ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
- ¥15 相敏解调 matlab
- ¥15 求lingo代码和思路