I want to code a program that can calculate the area of a triangle based on the user's input, I am Brazilian so the print is in Portugues, however i think that it won't change anynthing. So my problem is the first "if" runs perfect, but the second "if" only prints the first line (Voce tem o valor dos 3 lados? (s ou n): ) and the program stop running, i can't find where my mistake is if someone can help me it would be good, and if the portuguese is making it more difficult let me know and I translate it. thanks.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void triangulo(){
int angulo;
float a, b, c, s, area, base, altura, seno, rad;
char resposta1, resposta2;
printf("Voce tem os valores da base e da altura? (s ou n): ");
scanf("%c", &resposta1);
if (resposta1 == 's'){
printf("Digite a base do triangulo : ");
scanf("%f", &base);
printf("Digite a altura do triangulo : ");
scanf("%f", &altura);
area = (base * altura)/2;
printf("A area do triangulo eh : %f", area);
}
else{
if(resposta1 == 'n'){
printf("Voce tem o valor dos 3 lados? (s ou n): ");
scanf("%c", &resposta2);
if(resposta2 == 's'){
printf("Digite o valor do lado : ");
scanf("%f", &a);
printf("Digite o valor do lado : ");
scanf("%f", &b);
printf("Digite o valor do lado : ");
scanf("%f", &c);
s = (a + b + c)/2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("A area do triangulo eh : %f", area);
}
else{
if(resposta2 == 'n'){
printf("Digite o lado : ");
scanf("%f", &a);
printf("Digite o outro lado : ");
scanf("%f", &b);
printf("Digite o angulo entre esses dois lados : ");
scanf("%d", &angulo);
rad = 3.14159265358979323846/180;
seno = sin(rad * angulo);
area = (a * b * seno)/2;
printf("A area do triangulo eh : %f", area);
}
}
}
}
return;
}
int main (void){
triangulo();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire