3
#include <stdio.h>
typedef struct
{
char nome[10];
float altura;
float peso;
char cpf[12];
char sexo[10];
}Dados;
void imc(Dados x);
char consulte[12];
void imc(Dados x[1])
{
int i,c;
for(i=0;i<=1;i++)
{
if (consulte==x.cpf)
{
if(x.peso<18.5)
{
printf("Baixo do peso.");
}
else
{
if((x.peso>=18.5) && (x.peso<25))
{
printf("Peso adequado.");
}
else{
if((x.peso>=25) && (x.peso<30))
{
printf("Sobrepeso.");
}
else
{
if(x.peso>=30)
{
printf("Obesidade.");
}
}
}
}
}
}
}
int main ()
{
int i;
char verdadeiro[10];
Dados pessoas[1];
for(i=0;i<=1;i++)
{
fflush(stdin);
printf("Digite o nome da %i pessoa: ",i);
scanf("%s", &pessoas.nome);
fflush(stdin);
printf("Digite a altura da %d pessoa: ",i);
scanf("%f", &pessoas.altura);
fflush(stdin);
printf("Digite o cpf da %d pessoa: ",i);
scanf("%s", &pessoas.cpf);
fflush(stdin);
printf("Digite o peso da %d pessoa: ",i);
scanf("%f", &pessoas.peso);
fflush(stdin);
printf("Digite o sexo da %d pessoa: ",i);
scanf("%s", &pessoas.sexo);
fflush(stdin);
}
do
{
printf("Digite o nome do cpf da pessoa que você deseja ver o peso:");
scanf("%s", &consulte);
imc(pessoas[1]);
printf("Você quer continuar? Digite[S/N]");
scanf("%s", &verdadeiro);
}
while (verdadeiro!="N");
return 0;
}
Description of the problem:
When running I cannot access the user by Cpf, in the code use if’s because I want possibilities for the imc
. I don’t know what exactly is wrong.
I still think the mistake is in if
, because I want to compare the (variable) con
which is the same as the (variable) consulte
which is where Cpf is that the user wants to consult con
,with the x[i].cpf
to see if Cpf is right.
At this point I compare I think it does not access the if and only asks if user wants to continue. And it does not show what I want to show the Imc
.
When running I can’t access the user by Cpf, in the code I use if’s because I want possibilities for the imc. I don’t know what exactly is wrong.
– Guilherasmin silva
Thanks for correcting my code, I was lost trying to fix.
– Guilherasmin silva
I still think the error is in the if, because I want to compare the con that is the same as (variable)see that is where Cpf is that the user wants to query there compare the con,with x[i]. Cpf to see if Cpf is right. At this point I compare it does not access the if and only asks if user wants to continue.
– Guilherasmin silva
Okay. I’ll edit it.
– Guilherasmin silva
To compare strings (char array) in C you must use the strcmp function of <string. h> and not the operator ==.
– anonimo
Declare your imc function with Data parameter x[] and call such a function by informing the people argument (imc(people[]);).
– anonimo
Thank you, Anonimo. I was able to fix my code, thanks to you thanks for the help. Stay with God.
– Guilherasmin silva
@anonymity create a response
– Andrei Coelho