它會自動執行默認設置,而不是我的任何情況。任何想法我做錯了什麼?我的開關盒有什麼問題?
#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 2011-01-24 19:58:37