c语言写的程序出bug了

Python012

c语言写的程序出bug了,第1张

改成这样:

int main()

{

int flag=0

double faHeight, moHeight,YouHeight

char sport, sex, diet

printf("Welcome to height test\n")

printf("please input your sex,M or F\n")

scanf("%c", &sex)

getchar()

printf("please input your father and mother's height\n")

scanf("%lf,%lf", &faHeight, &moHeight)

getchar()

printf("Do you like sport? Y or N\n")

scanf("%c", &sport)

getchar()

printf("Do you have a good diet? Y or N\n")

scanf("%c", &diet)

getchar()

if (sex == 'F')

{

flag = flag + 1

}

if (sport == 'Y')

{

flag = flag + 10

}

if (diet == 'Y')

{

flag = flag + 100

}

switch (flag)

{

case 1:

YouHeight = (faHeight + moHeight)*0.54

break

case 11:

YouHeight = (faHeight + moHeight)*0.54 * 1.02

break

case 111:

YouHeight = (faHeight + moHeight)*0.54*1.035

break

case 101:

YouHeight = (faHeight + moHeight)*0.54*1.015

break

case 0:

YouHeight = (faHeight*0.9232 + moHeight) / 2

break

case 10:

YouHeight = (faHeight*0.923 + moHeight) / 2 * 1.02

break

case 110:

YouHeight = (faHeight*0.923 + moHeight) / 2 * 1.035

break

case 100:

YouHeight = (faHeight*0.923 + moHeight) / 2 * 1.015

break

default:

printf("you input the wrong word\n")

break

}

printf("You heingt is %f\n", YouHeight)

getchar()

return 0

}

#include<stdio.h>

void main()

{

char filename[30]

FILE *fpt

printf("Please create a name for the file.\n")

scanf_s("%s", filename,30)//scanf_s在输入字符串的时候,要指定大小

fopen_s(&fpt,filename, "w")

if (fpt == NULL)

{

printf("No file is created.")

}

else

{

int c

while ((c = getchar()) != EOF)//这里应该是EOF 

{

_fputchar(c)

}

fprintf(fpt, "CTRL + A is a correct ending.\n")

fclose(fpt)

}

}