距离计算器,一切正常,直到程序达到功能,而不是程序停止运行。我尝试从我在主函数中调用函数的行中删除void
and s,但仍然没有。int
#include <stdio.h>
#include <math.h>
void distanceFunc(int x2, int x1, int y2, int y1, int distance);
int main ()
{
int action = 0;
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
int distance = 0;
printf("Welcome to my calculator!\n");
printf("1 - Calc distance between 2 points\n");
printf("2 - Calc hypotenuse of triangle\n");
printf("3 - Calc area and perimeter of circle\n");
printf("4 - Calc area of rectangle\n");
printf("5 - Calc are of square\n");
printf("6 - Exit\n");
scanf("%d", &action);
if (action == 1)
{
printf("Enter point1 coordinates: ");
scanf("%d %d", &x1, &y1);
printf("Enter point2 coordinates: ");
scanf("%d %d", &x2, &y2);
void distanceFunc(int x2, int x1, int y2, int y1, int distance);
}
return 0;
}
void distanceFunc(int x2, int x1, int y2, int y1, int distance)
{
distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
printf("Distance is %f\n", distance);
}