자동으로 기본값을 수행하며 내 경우는 수행하지 않습니다. 내가 뭘 잘못하고 있는거야?스위치 케이스에 문제가 있습니까?
#include <stdio.h>
#include <math.h>
int main()
{
float x,y,z,p,a,h;
int d;
printf ("\n This program calculates Perimeter, Area, or Hypotenuse of a right triangle based on user choice\n\n\n\n");
/* Prompt user to select which calculation is to be performed */
printf ("If you would like to calculate Perimeter, type P\nIf you would like to calculate Area, type A\nIf you would like to calculate
Hypotenuse, type H\n\n") ;
scanf ("%f,%f,%f",&p,&a,&h);
switch(d)
{
case('p'):
printf("/n You have chosen to do a perimeter calculation/n");
printf("/n Input the two side lengths of the right triangle separated by a space/n");
scanf("%f,%f",&x,&y);
z = pow (x,2) + pow (y,2);
p = x + y + z;
printf("\nLength of side A entered=%f\n",x);
printf("\nLength of side B entered=%f\n",y);
printf("\nCalculated Perimeter=%f\n",p);
break;
case('a'):
printf("/n You have chosen to do an area calculation/n");
printf("/n Input the two side lengths of the right triangle separated by a space/n");
scanf("%f,%f",&x,&y);
z = pow(x,2) + pow(y,2);
p = x + y + z;
a = (x * y)/2;
printf("\nLength of side A entered=%f\n",x);
printf("\nLength of side B entered=%f\n",y);
printf("\nCalculated area=%f\n",a);
break;
case('h'):
printf("/n You have chosen to do a hypotenuse calculation/n");
printf("/n Input the two side lengths of the right triangle separated by a space/n");
scanf("%f,%f",&x,&y);
z = pow (x,2) + pow (y,2);
printf("\nLength of side A entered=%f\n",x);
printf("\nLength of side B entered=%f\n",y);
printf("\nCalculated Hypotenuse=%f\n",z);
break;
default:
printf("/n wow...how did that even happen. Please put in a valid letter next time. /n");
}
}
D는 초기화되지 내가 무슨 값을 할당해야 – Mauricio