#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)
4 个解决方案
#1
vs2015的话,应该有一大堆警告信息吧, 反正就是关于类型不安全的
#2
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;
}
#3
按照你的指点问题已经解决,我怎么样把分给你?
我刚自学C语言没几天,有一点不太明白:
为什么 这一句”scanf("%lf %d %lf", &number1, &operation, &number2);“要加&,
而这里”result = number1 + number2;
printf("= %f\n", result);“却不能加呢?
我刚自学C语言没几天,有一点不太明白:
为什么 这一句”scanf("%lf %d %lf", &number1, &operation, &number2);“要加&,
而这里”result = number1 + number2;
printf("= %f\n", result);“却不能加呢?
#4
点结帖按钮。
因为scanf是这样规定的,你可以理解成要将输入的数据写入一个内存地址,由于是地址,所以要加&
因为scanf是这样规定的,你可以理解成要将输入的数据写入一个内存地址,由于是地址,所以要加&
#1
vs2015的话,应该有一大堆警告信息吧, 反正就是关于类型不安全的
#2
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;
}
#3
按照你的指点问题已经解决,我怎么样把分给你?
我刚自学C语言没几天,有一点不太明白:
为什么 这一句”scanf("%lf %d %lf", &number1, &operation, &number2);“要加&,
而这里”result = number1 + number2;
printf("= %f\n", result);“却不能加呢?
我刚自学C语言没几天,有一点不太明白:
为什么 这一句”scanf("%lf %d %lf", &number1, &operation, &number2);“要加&,
而这里”result = number1 + number2;
printf("= %f\n", result);“却不能加呢?
#4
点结帖按钮。
因为scanf是这样规定的,你可以理解成要将输入的数据写入一个内存地址,由于是地址,所以要加&
因为scanf是这样规定的,你可以理解成要将输入的数据写入一个内存地址,由于是地址,所以要加&