user-0 提问: 新手c语言求解，新手比较穷，没积分

回复:
user: user-1

user: user-0
content: 引用 2 楼 user-1的回复: 第162行多打了，修改如下：	while (scanf("%f", &x) != 1 ) 老哥，谢谢了又是你

user: user-1
content: 第162行多打了，修改如下：	while (scanf("%f", &x) != 1 )

user: user-1
content: 修改如下，供参考：#include <stdio.h> int main() { 	char ch,c, s[2]; 	int m, n,l,i,a; 	float x, y,z; 	printf("Enter the operation of your choice:"); 	printf("\na.  add         s.subtract\n"); 	printf("m.  multiply       d.divide\n"); 	printf("q.quit\n"); 	scanf_s("%s", s,2); 	ch = s[0]; 	rewind(stdin); 	while (ch != 'q') 	{ 		switch (ch) 		{ 			case 'a': 			{  printf("Enter  first number:\n"); 			while (scanf_s("%f", &x) != 1) 			{ 				//char   c ;                                 while ((c = getchar())!='\n')                                        putchar(c); 				printf(" is not a number ,the correct number such as -1 ,3 or 25,please enter again\n"); 				} 				for (i = 10,m=0,l=1;l != 0;i *= 10) 				{ 				a = (int)(x * i); 				l = a % 10; 				if (l != 0) 					 m++; 			 				} 				printf("Enter second number:\n"); 				while (scanf_s("%f", &y) != 1) 				{ 					//c = 0; 				while ((c=getchar()) != '\n') 					putchar(c); 				printf(" is not a number ,the correct number such as -1 ,3 or 25,please enter again\n"); 				} 				for (i = 10, n = 0,l=1;l != 0;i *= 10) 				{ 				a = (int)(x * i); 				l = a % 10; 				if (l != 0) 					n++;  				} 				z = x + y; 				if (m == 0 && n == 0) 				printf("%.*f+%.*f=%.*f\n", m, x,m, y,m, z); 				else 				{ 					if (m > n)  						printf("%.*f+%.*f=%.*f\n", m, x,m, y,m, z); 					else 						printf("%.*f+%.*f=%.*f\n", n, x,n, y,n, z); 				} 				  				break; 			} 			case 's': 			{  printf("Enter  first number:\n"); 			while (scanf_s("%f", &x) != 1) 			{ 				 //char  c = 0; 				while ((c=getchar()) != '\n') 					putchar(c); 				printf(" is not a number ,the correct number such as -1 ,3 or 25,please enter again\n"); 			} 			for (i = 10, m = 0,l=1;l != 0;i *= 10) 			{ 				a = (int)(x *i); 				l = a % 10; 				if (l != 0) 					m++;  			} 			printf("Enter second number:\n"); 			while (scanf_s("%f", &y) != 1) 			{ 				 //char  c = 0; 				while ((c=getchar()) != '\n') 					putchar(c); 				printf(" is not a number ,the correct number such as -1 ,3 or 25,please enter again\n"); 			} 			for (i = 10, n = 0,l=1;l != 0;i *= 10) 			{ 				a = (int)(x * i); 				l = a % 10; 				if (l != 0) 					n++;  			} 			z = x - y; 			if (m == 0 && n == 0) 				printf("%.*f-%.*f=%.*f\n", 0, x,0, y, 0,z); 			else 			{ 				if (m > n)  					printf("%.*f-%.*f=%.*f\n", m, x, m, y, m, z); 				else 					printf("%.*f-%.*f=%.*f\n", n, x, n, y, n, z); 			}  			break; 			} 			case 'm': 			{  printf("Enter  first number:\n"); 			while (scanf_s("%f", &x) != 1) 			{                                 //char c = 0; 				while ((c=getchar()) != '\n') 					putchar(c); 				printf(" is not a number ,the correct number such as -1 ,3 or 25,please enter again\n"); 			} 			for (i = 10, m = 0,l=1;l != 0;i *= 10) 			{ 				a = (int)(x * i); 				l = a % 10; 				if (l != 0) 					m++;  			} 			printf("Enter second number:\n"); 			while (scanf_s("%f", &y) != 1) 			{ 				 // char c = 0; 				while ((c=getchar()) != '\n') 					putchar(c); 				printf(" is not a number ,the correct number such as -1 ,3 or 25,please enter again\n"); 			} 			for (i = 10, n = 0,l=1;l != 0;i *= 10) 			{ 				a = (int)(x * i); 				l = a % 10; 				if (l != 0) 					n++;  			} 			z = x * y; 			if (m == 0 && n == 0) 				printf("%.*f*%.*f=%.*f\n", 0, x,0, y,0, z); 			else 			{ 				if (m > n)  					printf("%.*f*%.*f=%.*f\n", m, x, m, y, m, z); 				else 					printf("%.*f*%.*f=%.*f\n", n, x, n, y, n, z); 			}  			break; 			} 			case 'd': 			{  printf("Enter  first number:\n"); 			while (scanf_s("%f", &x) != 1) != 1) 			{ 				//char c = 0; 				while ((c = getchar()) != '\n') 					putchar(c); 				printf(" is not a number ,the correct number such as -1 ,3 or 25,please enter again\n"); 			} 			for (i = 10, m = 0, l = 1;l != 0;i *= 10) 			{ 				a = (int)(x * i); 				l = a % 10; 				if (l != 0) 					m++;  			} 			printf("Enter second number:\n"); 			while (scanf_s("%f", &y) != 1 && !((y > -0.0000001) && (y < 0.0000001))) 			{ 				//char c = 0; 				while ((c = getchar()) != '\n') 					putchar(c); 				printf(" is not a number ,the correct number such as -1 ,3 or 25,please enter again\n"); 				if ((y > -0.0000001) && (y < 0.0000001)) 				{ 					printf("the divisor can not be 0. please enter again\n"); 					continue; 				} 			} 			for (i = 10, n = 0, l = 1;l != 0;i *= 10) 			{ 				a = (int)(x * i); 				l = a % 10; 				if (l != 0) 					n++; 			} 			z = x / y; 			if (m == 0 && n== 0) 				printf("%.*f/%.*f=%.*f\n", 0, x,0, y,0, z); 			else 			{ 				if (m > n)  					printf("%.*f/%.*f=%.*f\n", m, x, m, y, m, z); 				else 					printf("%.*f/%.*f=%.*f\n", n, x, n, y, n, z); 			}  			break; 			}  			case 'q': break; 			default : 			{ 				printf("Enter the operation of your choice:"); 				printf("\na.  add         s.subtract\n"); 				printf("m.  multiply       d.divide\n"); 				printf("q.quit\n"); 				scanf_s("%s", s, 2); 				ch = s[0]; 				continue; 			}  		} 		printf("Enter the operation of your choice:"); 		printf("\na.  add         s.subtract\n"); 		printf("m.  multiply       d.divide\n"); 		printf("q.quit\n"); 		scanf_s("%s", s, 2); 		ch = s[0]; 	} 	return 0; }