-2
How could I print the variable sex outside the if-else
(has to be outside of it).
This code is printing blank and I can’t understand why.
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <string.h>
int main(void)
{
setlocale(LC_ALL, "Portuguese");//habilita a acentuação para o português!
int escolha;
char sexo;
printf("Escolha uma das opções abaixo: ");
printf("\n1- Sou mulher ");
printf("\n2- Sou homem ");
scanf("%d", escolha);
if(escolha==1){
char sexo[]="Feminino";
}
else{
char sexo[]="Masculino";
}
printf("Você é do sexo: ");
printf(sexo);
return 0;
}
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero