//C language program
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
double number1 = 0.0;
double number2 = 0.0;
int operation = 0;
double result = 0.0;
printf(“\n请在里输入要计算数字\n”);
scanf(“%lf %c %lf\n”, &number1, &operation, number2);
switch (operation)
{
case 1:
result = number1 + number2;
printf(“= %f\n”, &result);
break;
case 2:
result = number1 – number2;
printf(“= %f\n”, &result);
break;
case 3:
result = number1 * number2;
printf(“= %f\n”, &result);
break;
case 4:
if (number2 == 0)
printf(“\n\n数字输入错误,除数不能为0!\n”);
else
result = number1 / number2;
printf(“= %f\n”, &result);
break;
default:
printf(“不正确的操作法!!!”);
break;
}
system(“pause”);
return 0;
}
按F5键后出现以下错误提示
Program: D:\Documents\Visual Studio 2015\Projects\TEST\Debug\TEST.exe
File: minkernel\crts\ucrt\inc\corecrt_internal_stdio_input.h
Line: 1581
Expression: result_pointer != nullptr
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
double number1 = 0.0;
double number2 = 0.0;
int operation = 0;
double result = 0.0;
printf(“\n请在里输入要计算数字\n”);
scanf(“%lf %c %lf\n”, &number1, &operation, number2);
switch (operation)
{
case 1:
result = number1 + number2;
printf(“= %f\n”, &result);
break;
case 2:
result = number1 – number2;
printf(“= %f\n”, &result);
break;
case 3:
result = number1 * number2;
printf(“= %f\n”, &result);
break;
case 4:
if (number2 == 0)
printf(“\n\n数字输入错误,除数不能为0!\n”);
else
result = number1 / number2;
printf(“= %f\n”, &result);
break;
default:
printf(“不正确的操作法!!!”);
break;
}
system(“pause”);
return 0;
}
按F5键后出现以下错误提示
Program: D:\Documents\Visual Studio 2015\Projects\TEST\Debug\TEST.exe
File: minkernel\crts\ucrt\inc\corecrt_internal_stdio_input.h
Line: 1581
Expression: result_pointer != nullptr
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
解决方案
80
1.scanf(“%lf %c %lf\n”, &number1, &operation, number2);这句不对
number2前面少了&,%c应该是%d吧,”\n”也要去掉
2.printf(“= %f\n”, &result);也不对,result前面多了&
number2前面少了&,%c应该是%d吧,”\n”也要去掉
2.printf(“= %f\n”, &result);也不对,result前面多了&
#include<stdio.h> #include<stdlib.h> int main(void) { double number1 = 0.0; double number2 = 0.0; int operation = 0; double result = 0.0; printf("\n请在里输入要计算数字\n"); scanf("%lf %d %lf", &number1, &operation, &number2); switch (operation) { case 1: result = number1 + number2; printf("= %f\n", result); break; case 2: result = number1 - number2; printf("= %f\n", result); break; case 3: result = number1 * number2; printf("= %f\n", result); break; case 4: if (number2 == 0) printf("\n\n数字输入错误,除数不能为0!\n"); else result = number1 / number2; printf("= %f\n", result); break; default: printf("不正确的操作法!!!"); break; } system("pause"); return 0; }