0
I’m starting in C... and it always happens that the compiler ignores the scanf
... but I do not understand why. This program is giving this error and I am not able to solve, if you can help me, thank you!
#include <stdio.h>
#include <string.h>
/* O programa deve perguntar qual a figura geométrica, e então pedir para o
usuário digitar os tamanhos dos lados e calcular a area.
*/
float quadrado(){
float lado;
printf("\nDigite o valor de cada lado: ");
scanf("%f", &lado);
return printf("\nA area do quadrado é de %f", (lado*2 ));
};
float retangulo(){
float base,altura;
printf("\nDigite o valor da altura: ");
scanf("%f", &altura);
printf("\nDigite o valor da base: ");
scanf("%f", &base);
return printf("A area do retangulo é de %f", (base*altura));
};
int main() {
char figura;
printf("Qual a figura geometrica? (quadrado ou retangulo)");
scanf("%c", &figura);
if(strcmp(&figura,"quadrado")){
quadrado();
} else if (strcmp(&figura,"retangulo")){
retangulo();
} else{
printf("Figura invalida");
}
}
You are setting your function
quadrado
as returning afloat
but in chargereturn
this function specifies what will be returned by the functionprintf
which, according to the manual. will be the number of bytes transmitted. Maybe you wanted to returnlado*2
. Iofcretangulo
. Note that in the calling function (main) you ignore what is returned by these functions. If it’s just to print what you want in your functionsvoid
and print and don’t give areturn
.– anonimo
The area of the square should not be
lado * lado
?– hkotsubo