运算的结果根本不对 大家帮我看看吧 不知道那里出问题了
主函数代码
#include <stdio.h>
int main() {
int x;
float a = 0, b = 0;
printf("请输入功能前的数字)
");
scanf_s("%d", &x);
switch (x)
{
case 1: {
printf("请输入要相加的数字");
scanf_s("%f%f", &a, &b);
float result = jiafa(a, b);
printf("%f", result);
}break;
case 2: {
printf("请输入要相减的数字");
scanf_s("%f%f", &a, &b);
float result = jianfa(a, b);
printf("%f", result);
}break;
case 3: {
printf("请输入要相乘的数字");
scanf_s("%f%f", &a, &b);
float result = chengfa(a, b);
printf("%f", result);
}break;
case 4: {
printf("请输入要相除的数字");
scanf_s("%f%f", &a, &b);
float result = chufa(a, b);
printf("%f", result);
}break;
default:printf("选择功能错误 请重新选择");
break;
}
计算函数代码
#include <stdio.h>
float jiafa(float x, float y) {
float sum;
sum = x + y;
return sum;
}
float jianfa(float x, float y) {
float sum;
sum = x - y;
return sum;
}
float chengfa(float x, float y) {
float sum;
sum = x * y;
return sum;
}
float chufa(float x, float y) {
float sum;
sum = x / y;
return sum;
}