I'm new to programming; the question of the question is this:
Given as input data the name, height and sex (M or F) of a person, calculate and show your ideal weight using the following formulas:
• for males: ideal weight = (72.7 * height) - 58
• for female: ideal weight = (62.1 * height) - 44.7
However, in the code, it does not read the Male and Female data.
I wonder why I can not read?
Is scanf the best way to do character readings?
Thank you very much.
#include<stdio.h>#include<locale.h>#include<stdlib.h>#include<string.h>intmain(void){setlocale(LC_ALL,"");
unsigned char nome[50],gen;
float alt,resultado;
printf("Qual o seu nome?\n");
scanf("%s",&nome);
printf("Qual o seu genero [M] ou [F] para feminino?\n");
scanf("%c",&gen);
printf("Qual a sua altura?\n");
scanf("%f",&alt);
if (gen == 'M') {
resultado == (72.7 * alt) - 58;
printf("O seu peso ideal é: %.1f",resultado);
} else if (gen == 'F') {
resultado == (62.1 * alt) - 44.7;
printf("O seu peso ideal é: %.1f",resultado);
} else {
printf("\n letra inválida, informe M ou F\n");
}
}