C 如何修复分割错误?

C 如何修复分割错误?,c,C,我写了这个简单的程序,当我运行它的时候,它说分割错误。我怎么修理它?只有程序的第一行运行 #include <stdio.h> int main() { int items; float price, pprice, amt, HST; printf("Enter the number of items :", items); scanf(" %d", items); printf("Enter the unit price :", price); scanf

我写了这个简单的程序,当我运行它的时候,它说分割错误。我怎么修理它?只有程序的第一行运行

#include <stdio.h>


int main()
{
int items;
float price, pprice, amt, HST;

printf("Enter the number of items :", items);
    scanf(" %d", items);

printf("Enter the unit price :", price);
    scanf(" %f", price);

pprice = items * price;
printf("Purchase price :pprice\n");

printf("HST (13%) : 1.64\n");
HST = 1.64;
amt = HST + pprice;

printf("Total price: amt\n\n");



return 0;
}
#包括
int main()
{
国际项目;
浮动价格、pprice、amt、HST;
printf(“输入项目数:”,项目);
scanf(“%d”,项目);
printf(“输入单价:”,价格);
scanf(“%f”,价格);
pprice=项目*价格;
printf(“购买价格:pprice\n”);
printf(“HST(13%):1.64\n”);
HST=1.64;
金额=HST+pprice;
printf(“总价:金额\n\n”);
返回0;
}
应该是

scanf(" %d", &items);
scanf(" %f", &price);
提供变量的地址

编辑:

您的printf也有问题

printf("Enter the number of items :", items);
应该是公正的

printf("Enter the number of items :");

请查看以下链接:


当扫描中的变量不使用符号(&)时,通常会发生分段错误。。。因此,请尝试将“与”附加到变量


如scanf(“%d”项和项目)

带调试器。您可以使用调试器修复它。首先,打开编译器警告。还有OP的printf语句:
printf(“输入项数:”,items)
还有这一行
printf(“购买价格:pprice\n”)应该是
printf(“采购价格:%f\n”,pprice),还有两行类似的代码同上。@WeatherVane是的,此代码存在许多问题:)
printf("Enter the number of items :");
printf("Enter the unit price : %f", price);