#include<stdio.h>
#include<conio.h>
void main()
{
char sexo;
float alt,peso;
printf("Qual o seu sexo? (M/F)");
sexo=getch();
printf("Insira a sua altura: ");
scanf("&f", &alt);
if (sexo=m||sexo=M||sexo=f||sexo=F)
{
if (sexo=m||sexo=M)
peso=(72.7*alt)-58;
else
peso=(62.1*alt)-44.7;
printf("O peso recomendado para o seu sexo e %.2fKg",peso);
}
else
printf("Sexo invalido");
}
一旦我尝试编译它,我就会在第 11 行收到错误消息:
error: 'm' undeclared (first use in this function)
error: 'M' undeclared (first use in this function)
error: 'f' undeclared (first use in this function)
error: 'F' undeclared (first use in this function)
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===||
有人知道发生了什么吗?
最佳答案
你使用 m & M & f & F 的方式就像它们是变量而不是字符 这就是你想要做的
2- 比较运算符是 == 而不是 =(这是赋值运算符)
if (sexo=='m'||sexo=='M'||sexo=='f'||sexo=='F')
关于c - 我无法在 if 语句中使用字符名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54916063/