我是c新写的,我正在尝试使用switch语句根据输入调用函数。不确定为什么这不起作用。很抱歉,如果这是在错误的地方发布或已经得到解答但我找不到任何内容。
int choice;
printf("---Menu---\n");
printf("1 Add Two Vectors\n");
printf("2 Subtract Two Vectors\n");
printf("3 Calculate Euclian Distance\n");
printf("4 Exit The Program\n");
printf(" Please select an option (1, 2, 3, or 4): ");
scanf("&d", &choice);
switch (choice){
case 1:
addVectors();
break;
case 2:
subVectors();
break;
case 3:
euclianDistance();
break;
/ *这是被称为* /
的函数printf("Please input Vector 1 X and Y coordinate separated by a space: ");
scanf("&d", "&d", &coordinateX1, &coordinateY1);
printf("Please input Vector 2 X and Y coordinate separated by a space: ");
scanf("&d", "&d", &coordinateX2, &coordinateY2);
vectorSumX = coordinateX1 + coordinateX2;
vectorSumY = coordinateY1 + coordinateY2;
printf("Sum of vectors is: (", &vectorSumX), printf(",", &vectorSumY), printf(")");
return 0;
谢谢!
答案 0 :(得分:1)
&vectorSumX
将为您提供变量vectorSumX的地址!您没有使用任何占位符来给出答案!相反,你应该使用
printf("Please input Vector 1 X and Y coordinate separated by a space: ");
scanf("%d,%d", &coordinateX1, &coordinateY1);
printf("Please input Vector 2 X and Y coordinate separated by a space: ");
scanf("%d,%d", &coordinateX2, &coordinateY2);
int vectorSumX = coordinateX1 + coordinateX2;
int vectorSumY = coordinateY1 + coordinateY2;
printf("Sum of vectors is: (");
printf("%d", vectorSumX);
printf(",");printf("%d",vectorSumY);
printf(")");
在功能上得到答案!