简介:我正在构建一个简单的程序来输入用户的两个数字的坐标并打印这些坐标之间的距离.
问题:问题是编译器不允许我将其设置y1为float变量.如果我更改y1为ycord1或任何其他变量名称,该程序工作正常.
我没有问题设置x1和z1浮动变量,问题只有y1.
这是我得到的错误的屏幕截图:

代码:
#include <stdio.h>
#include <math.h>
float square(float, float);
float x1, y1, z1;
float x2, y2, z2;
float distance = 0;
int main(int argc, const char * argv[]) {
printf("Enter coordinates of Point 1: ");
scanf("%f, %f, %f", &x1, &y1, &z1);
printf("Enter coordinates of Point 2: ");
scanf("%f, %f, %f", &x2, &y2, &z2);
distance = sqrtf(square (x2, x1) + square (y2, y1) + square (z2, z1));
printf("Distance between the 2 points is %.3f\n\n", distance);
return 0;
}
float square(float a, float b)
{
float c = a - b;
c = c * c;
return c;
}
Run Code Online (Sandbox Code Playgroud)
我尝试了两种不同的编译器,但两者都产生了同样的错误.
我尝试Is y1 a reserved variable in C在Google上搜索,但找不到任何有意义的结果.如果我还需要提供替换y1为任何其他变量时代码的屏幕截图,请告诉我.