注册 登录
编程论坛 C语言论坛

为什么结果都是一样的,求助!

浩浩浩hh 发布于 2021-10-28 18:06, 1444 次点击
#include<stdio.h>
int main()
{
    char sex;
    float faHeight,moHeight,clHeight;
   
    printf("请输入你的性别:");
  sex=getchar();
  scanf("%c",&sex);

printf("请输入你父亲的身高:");
scanf("%f",&faHeight);

    printf("请输入你母亲的身高:");
    scanf("%f",&moHeight);
   
    if(sex='F'){
    clHeight=(faHeight+moHeight)*0.54;}
    else{
    clHeight=(faHeight*0.923+moHeight)/2;}
        printf("成人时身高是%.2fcm",clHeight);
   return 0;
}
2 回复
#2
自由而无用2021-10-28 18:31
if(sex='F'){
    clHeight=(faHeight+moHeight)*0.54;}
    else{
#3
自由而无用2021-10-28 18:40
//online parser: https://www.bccn.net/run/
程序代码:
#include <stdio.h>

int main(int argc, char *argv[])
{
    char gender;
    float Dad_Ht, Mummy_Ht, __Ht;
#define V_DBG
#ifndef V_DBG
    printf("请输入你的性别:");
    /* scanf("%c", &gender); */
    printf("请输入你父亲的身高:");
    /* scanf("%f", &Dad_Ht); */
    printf("请输入你母亲的身高:");
    /* scanf("%f", &Mummy_Ht); */
#else
#define _GENDER 'F'
    gender = _GENDER;
    Dad_Ht = 180.01;
    Mummy_Ht = 170.25;
#endif
#define to_upper(_c) (_c &= ~0x20)
    if (to_upper(gender) == 'M')
        __Ht = (Dad_Ht + Mummy_Ht) * 0.54;
    else if (to_upper(gender) == 'F')
        __Ht = (Dad_Ht * 0.923 + Mummy_Ht) / 2;
    else __Ht = 0;
        
    printf("成人时身高是%.2fcm", __Ht);
        
    return 0;
}


output sample:
成人时身高是168.20cm
#4
浩浩浩hh2021-10-28 18:45
问一下我这个错在哪里呜呜
#5
apull2021-10-28 23:14
if(sex='F') 判断要用 ==
1