Hello I'm a noob and I wrote this piece of code:
When I want to calculate hypotenuse, I have the integer value of it and no remainder. I tried to make Hyp variable float type but I can't get it.Code:#include <stdio.h> #include <math.h> int CalcHyp(int cat1, int cat2); int CalPer(int l1, int l2, int l3); int main() { int l1,l2,l3,cat1,cat2; int answer; printf("Choose options in calculator: \n1 - perimeter \n2 - hypotenuse\n" "Exit (any other key or letter)\n"); scanf("%d", &answer); switch(answer) { case 1: printf("Insert the three lenghts:\n"); scanf("%d %d %d", &l1,&l2,&l3); printf("This is the perimeter: %d\n\n",CalPer(l1,l2,l3)); main(); break; case 2: printf("Insert the two catheti:\n"); scanf("%d %d", &cat1,&cat2); printf("This is the hypotenuse: %f\n", CalcHyp(cat1,cat2)); main(); break; default: printf("Exit\n"); } } int CalcHyp(int cat1, int cat2) { float Hyp; Hyp = sqrt(pow(cat1,2)+pow(cat2,2)); return Hyp; } int CalPer(int l1, int l2, int l3) { int perimeter; perimeter = l1+l2+l3; return perimeter; }
Hope you understand what's written in printfs cause I'm not a native speaker. Thanks for help.



1Likes
LinkBack URL
About LinkBacks




)