c语言身高预测后,是否进行下次预测的选择问题

img

img


想知道如何进行第二个问题如何增加对话功能,提示是否继续进行预测就行,不必回答第一个问题。

/*********仅供参考***************/
#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;
}