|
while 到底该镇么用?
while ( choice > 3 ) { .......
} /* end while */
这样可以,但是如果。
while ( choice >3 && choice <1 ) { .... } /* end while */
这样就不能了,经该怎么写??
#include <stdio.h>
main() {
char NAME[30] ;
float a, r , p , PI ;
int choice = 5;
while ( NAME[0] != 'q' ) {
printf("Type " q " to exit\n") ;
printf("Enter Your Name:");
scanf(" %[^\n]" , NAME ) ;
if (NAME[0] == 'q') break ; /* program terminated */
printf("\nHi %s welcome to Area and Circumference Calculator\n" , NAME) ;
while ( ((choice >3) && (choice <1) ) ) {
printf("Select Value of ¦Ð:\n") ;
printf("1) ¦Ð= 3.142\n") ;
printf("2) ¦Ð= 3.14159\n") ;
printf("3) ¦Ð= 3.14159265\n") ;
printf("Enter Your Choice ( 1/2/3 ) :") ;
scanf(" %d" , &choice );
/* Control Statement ( Value of PI ) */
switch (choice) {
case 1:
PI = 3.142 ;
break ;
case 2:
PI = 3.14159 ;
break ;
case 3:
PI = 3.14159265 ;
break ;
default:
printf("\nInvalid Choice\n\n") ;
} /* end switch */
} /* end while */
printf("Enter Value of Radius: ") ;
scanf(" %f" , &r ) ;
/* Calculation */
a = PI * r * r ;
p = 2 *PI * r ;
printf("\nArea = %f\n" , a ) ;
printf("Circumference = %f\n" , p ) ;
printf("Thanks for Trying\n\n");
} /* end main while */
}
[ 本帖最后由 onlylonly 于 8-11-2005 02:08 AM 编辑 ] |
|