跟着要求写就可以了,不难的。
这里只需要注意每次输入以后的回车要再用一个getchar()吸收,防止回车作为字符存进变量。
如果对你有帮助的话欢迎关注我的博客,定期更新简单的算法问题与学习笔记。
举手之劳,祝你学业进步!
#include<stdio.h>
int main(){
float height=0;
float faheight,moheight;
char sex,sports,diet;
printf("sex:");
scanf("%c",&sex);
getchar();
printf("faheight:");
scanf("%f",&faheight);
getchar();
printf("moheight:");
scanf("%f",&moheight);
getchar();
printf("sports:");
scanf("%c",&sports);
getchar();
printf("diet:");
scanf("%c",&diet);
if (sex == 'M'){
height = (faheight+moheight)*0.54;
}else{
height = (faheight*0.923+moheight)/2;
}
if (sports == 'Y'){
height = height + height*0.02;
}
if (diet == 'Y'){
height = height + height*0.015;
}
printf("height:%f",height);
return 0;
}
第一题:
#include<bits/stdc++.h>//万能头
using namespace std;
int main() {
float faheight/*爸爸身高*/,moheight/*妈妈身高*/,h/*预测身高*/;//定义
char sex/*性别*/,sports/*喜爱运动*/,diet/*饮食习惯*/;//定义
cin>>sex>>faheight>>moheight>>sports>>diet;//输入
if(sex=='F'){//性别判断
h=(faheight*0.923+moheight)/2;
}else{
h=(faheight+moheight)*0.54;
}
if(sports=='Y'&&diet=='y'){//额外增加身高
h*=1.035;
}else if(sports=='Y'){
h*=1.02;
}else if(diet=='y'){
h*=1.015;
}cout<<h;
}
第二题不会......