# 这个程序是处理四则运算的，但是出了点有关问题，也不是很完美，希望大家改改，多谢

www.MyException.Cn  网友分享于：2013-04-23  浏览：5次

[code=C/C++][/code]
#include<stdio.h>
char put_choise();
float subract_number();
float multiply_number();
float divide_number();
float judge();
float judge2();

int main()
{

char getch;

while((getch=put_choise())!='q')
{
switch(getch)
{
case 'a':
break;
case 's':
subract_number();
printf("sburact_number的结果是：%.3f\n",subract_number());
break;
case 'm':
multiply_number();
break;
case 'd':
divide_number();
break;
}
}
return 0;}

//
char put_choise()
{
printf("Enter the operation of choise:\n ");
printf("m.multiply\t\t\td.divide\nq.quit\n");
return (getchar());

}

//
{
float first_number,second_number;
printf("Enter first number:");

first_number=judge();
printf("Enter second number");

second_number=judge();
return (first_number+second_number);
}

//

float subract_number()
{
float first_number,second_number;
printf("Enter first number:");

first_number=judge();
printf("Enter second number");

second_number=judge();
return (first_number-second_number);
}

//
float multiply_number()
{
float first_number,second_number;
printf("Enter first number:");

first_number=judge();
printf("Enter second number");

second_number=judge();
return (first_number*second_number);
}

//
float divide_number()
{
float first_number,second_number;
printf("Enter first number:");

first_number=judge();
printf("Enter second number");

second_number=judge();
return (first_number/second_number);
}

//
float judge()
{
float first_num;
char ch;
while(scanf("%f",&first_num)==0)
{
while((ch=getchar())!='\n')
putchar(ch);

printf("Please Enter a number ,such as 2.5,-1.78E8,or3:");
}

return first_num;

}

//
float judge2()
{
float second_num;
char ch;
while(scanf("%f",&second_num)!=1)
{
while((ch=getchar())!='\n')
putchar(ch);

printf("Please Enter a number ,such as 2.5,-1.78E8,or3:");
}

return second_num;

}

------解决方案--------------------

C/C++ code
```
#include<stdio.h>

char put_choise();
float subract_number();
float multiply_number();
float divide_number();
float judge();
float judge2();

int main()
{

char getch;

while((getch=put_choise())!='q')
{
switch(getch)
{
case 'a':
break;
case 's':
printf("sburact_number的结果是：%.3f\n",subract_number());
break;
case 'm':
multiply_number();
break;
case 'd':
divide_number();
break;
}

}
return 0;}

//
char put_choise()
{
printf("Enter the operation of choise:\n");
printf("m.multiply\t\td.divide\nq.quit\n");
fflush(stdin);
return (getchar());

}

//
{
float first_number,second_number;
printf("Enter first number:");

first_number=judge();
printf("Enter second number:");

second_number=judge();
return (first_number+second_number);
}

//

float subract_number()
{
float first_number,second_number;
printf("Enter first number:");

first_number=judge();
printf("Enter second number");

second_number=judge();
return (first_number-second_number);
}

//
float multiply_number()
{
float first_number,second_number;
printf("Enter first number:");

first_number=judge();
printf("Enter second number:");

second_number=judge();
return (first_number*second_number);
}

//
float divide_number()
{
float first_number,second_number;
printf("Enter first number:");

first_number=judge();
printf("Enter second number:");

second_number=judge();
return (first_number/second_number);
}

//
float judge()
{
float first_num;
char ch;
scanf("%f",&first_num);
/*    while(scanf("%f",&first_num)==0)
{
while((ch=getchar())!='\n')
putchar(ch);

printf("Please Enter a number ,such as 2.5,-1.78E8,or3:");
}

*/    return first_num;

}

//
float judge2()
{
float second_num;
char ch;
scanf("%f",&second_num);
/*    while(scanf("%f",&second_num)!=1)
{
while((ch=getchar())!='\n')
putchar(ch);

printf("Please Enter a number ,such as 2.5,-1.78E8,or3:");
}
*/
return second_num;

}
```