#include <stdio.h>
int inputd(char msg[],
double min,
double max,
double num0,
double *num)
{
double b;
if(min<0){ return 2; };
if(max<min){ return 2; };
if(num0<min){ return 2; };
if(num0>max){ return 2; };
do{
printf("\nPlease input a number(>=0) ! \n");
printf("(from %lf to %lf)\n", min, max);
printf("(if '-1' then INPUT = %lf)\n", num0);
printf("(if '-2' then END)\n");
printf("%s = ? ", msg);
scanf("%lf", &b);
if(b==-2){
return 1;
}else if(b==-1){
*num=num0;
break;
}else if(b<min){
printf("Too Small !!\n");
}else if(b>max){
printf("Too Large !!\n");
}else{
*num=b;
break;
};
}while(1);
return 0;
};
void main(){
int i;
double a;
i=inputd("ShiNCho", 50.0, 2.0*100.0, 170.0, &a);
if(i==0){
printf("ATaI = %lf \n", a);
i=inputd("TaIJu", 30.0, 100.0, 70.0, &a);
printf("I = %d \n", i);
if(i==0){
printf("ATaI = %lf \n", a);
};
};
if(i==2){
printf("Parameter Error\n");
};
}
|
prog.
|