-1
The program asks the sex of the user, then I asked for the opinion about a certain product( yes or no). As a way out, he should give me the total of people who gave yes and no, then the percentage of each sex that gave yes(woman) or no(man), but at the moment the program gives only the output of how many people gave no and yes, but not the percentage of each sex. I don’t know exactly how to proceed.
Code:
#include <stdio.h>
int main()
{
int i, escolha, sim, nao, feminino, masculino, sexo;
float mediamulher, mediahomem;
sim = 0;
nao = 0;
feminino = 0;
masculino = 0;
printf("Bem vindo!\n");
for (i = 1; i <= 4; i++)
{
printf("Entre com o sexo, sendo\n1 - Masculino e 2 - Feminino\nSelecione: ");
scanf("%d", &sexo);
printf("Voce considera esse produto aceitavel? 1-Sim ou 2-Nao: ");
scanf("%d", &escolha);
if (escolha == 1)
{
sim++;
}
if (escolha == 2)
{
nao++;
}
if (sexo == 2 && escolha == 1)
{
feminino++;
mediamulher = (feminino / 3) * 100;
}
if (sexo == 1 && escolha == 2)
{
masculino++;
mediahomem = (masculino / 20) * 100;
}
}
printf("Total de pessoa que deram sim: %d\nTotal de pessoa que deram nao:%d\n", sim, nao);
printf("A porcentagem de mulheres que deram sim foi: %.2f porcento.\n", mediamulher);
printf("A porcentagem de homens que deram nao foi: %.2f porcento.\n", mediahomem);
return 0;
}
You just count the answers yes and nay. To solve the problem you should count the yeses of the male public, the yeses of the female public, the noes of the male public and noes of the female public to then calculate averages and respective percentages to certain public.
– Augusto Vasques