/* ECP: FILEname=fig3_29.c */ /* 1*/ #include /* 2*/ #define Pi 3.1416 /* 3*/ #define Circle 1 /* 4*/ #define Rectangle 2 /* 5*/ #define Square 3 /* 6*/ main( void ) /* 7*/ { /* 8*/ int Choice; /* 9*/ double Dim1, Dim2; /*10*/ while( 1 ) /*11*/ { /*12*/ printf( "Enter %d for circle, ", Circle ); /*13*/ printf( "Enter %d for rectangle, ", Rectangle ); /*14*/ printf( "Enter %d for square: ", Square ); /*15*/ if( scanf( "%d", &Choice ) != 1 ) /*16*/ break; /*17*/ if( Choice == Circle ) /*18*/ { /*19*/ printf( "Enter radius: " ); /*20*/ if( scanf( "%lf", &Dim1 ) != 1 ) /*21*/ break; /*22*/ printf( "Shape is circle radius %.2f; ", Dim1 ); /*23*/ printf( "the area is %.2f\n", Dim1 * Dim1 * Pi ); /*24*/ } /*25*/ else if( Choice == Square ) /*26*/ { /*27*/ printf( "Enter side: " ); /*28*/ if( scanf( "%lf", &Dim1 ) != 1 ) /*29*/ break; /*30*/ printf( "Shape is square side %.2f; ", Dim1 ); /*31*/ printf( "the area is %.2f\n", Dim1 * Dim1 ); /*32*/ } /*33*/ else if( Choice == Rectangle ) /*34*/ { /*35*/ printf( "Enter length and width: " ); /*36*/ if( scanf( "%lf %lf", &Dim1, &Dim2 ) != 2 ) /*37*/ break; /*38*/ printf( "Shape is rectangle " ); /*39*/ printf( "length %.2f width %.2f; ", Dim1, Dim2 ); /*40*/ printf( "the area is %.2f\n", Dim1 * Dim2 ); /*41*/ } /*42*/ else /* Illegal Choice */ /*43*/ break; /*44*/ } /*45*/ }