C 我修改的代码中未处理的异常

C 我修改的代码中未处理的异常,c,arrays,printf,scanf,unhandled-exception,C,Arrays,Printf,Scanf,Unhandled Exception,我正在为硬件编写一个POS系统,我必须使用我的第一个代码,它使用了数百个变量,并使用数组将其更改为一个更紧凑的程序。这是我的新代码: #include <stdlib.h> #include <stdio.h> #include <conio.h> //--------------------------------------------------------------------------------------------

我正在为硬件编写一个POS系统,我必须使用我的第一个代码,它使用了数百个变量,并使用数组将其更改为一个更紧凑的程序。这是我的新代码:

    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>

//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//------------------------------------------Declaring-Variables--------------------------------------------
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------


//Discount Variables
int iPerPurchaseDiscountPercent = 0; //enter a number which will be later changed to a percentage 
int iFinalPurchaseDiscountPercent = 0;//enter a number which will be later changed to a percentage
float fPerPurchaseDiscountPercent = 0;//the percentage value of discount per item
float fFinalPurchaseDiscountPercent = 0;//percentage value of final dicount
float fPerPurchaseDiscountPrice = 0;//price at which discounts will be applied
float fFinalPurchaseDiscountPrice = 0;//price at which the final shop discount will be appled

//Array values for math
float fItemPrice[100] = { 0 }; //Price of Item
int   iItemQuantity[100] = { 0 }; //Quantity of that Item
float fBundleCost[100] = { 0 }; //Price before Discounts (fItemPrice[N] * fItemQuantity[N])
float fDiscountPerItem[100] = { 0 }; //What discount is recieved per item (fItemPrice[N] * iPerPurchaseAmount)
float fItemTotalDiscountRecieved[100] = { 0 }; //Total discount recieved on multiple items of same type (fDicountPerItem * iItemQuantity)
float fDiscountPrice[100] = { 0 };//Price for item after all discounts (fBundleCost - fDiscountRecieved)


//Values for while loop
bool bStillShopping = true;
int iItemCount = 0;
char cExitQuestion = 'y';


//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//-----------------------------------------------Prototyping-----------------------------------------------
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------


//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//------------------------------------------------Main-Loop------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
int main(void)
{
printf("Welcome to Blacketts bookstore!\t\t\t\t\t\tPOS V2\n");

//Taking values for the per item discounts
printf("Please enter the price that discounts per item will be applied: ");
flushall();
scanf("%f", &fPerPurchaseDiscountPrice); //takes the value at which items will be discounted
printf("Please enter the percentage to be applied at this price: ");
flushall();
scanf("%d", &iPerPurchaseDiscountPercent); //takes a value eg 10 to be later changed to .1 for 10%
fPerPurchaseDiscountPercent = iPerPurchaseDiscountPercent/100; //changes the int to a float and makes it appropriate for percentage calculations

//Taking values for the final purchase discount
printf("Please enter the price that end of sale discounts will be applied to: "); 
flushall();
scanf("%f", &fFinalPurchaseDiscountPrice); //takes the value at which the whole docket will be discounted by
printf("Please enter the percentage to be applied at this price: ");
flushall();
scanf("%d", &iFinalPurchaseDiscountPercent);//takes a value eg 5 to be later changed to .05 for 5%
fFinalPurchaseDiscountPercent = iFinalPurchaseDiscountPercent/100; //changes the int to a float and make it appropriate for percentage calculations

//While loop to take values and input them into appropriate places
while(bStillShopping == true)
{
    iItemCount = 1; // Counting how many items are being purchased, 0 = 1st item. therefore Total quantity Items must equal iItemCount+1

    printf("\nPlease enter the price of the first item to be purchased: "); //enter price of item
    flushall();
    scanf("%.2f", fItemPrice[iItemCount]);

    printf("Please enter the quantity of that item: "); //enter quantity
    flushall();
    scanf("%d", iItemQuantity[iItemCount]);

    printf("\nWould you like to enter any more Items? (y/n): "); //ask to continue
    flushall();
    scanf("%c", &cExitQuestion);

    if(cExitQuestion == 'n')
    {
        bStillShopping = false; //if dont want to continue exit the loop
    }
    else
    {
        iItemCount++; //if do continue increment item loop and ask for more variables
    }
}


getch();
}    
#包括
#包括
#包括
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//------------------------------------------声明变量--------------------------------------------
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//折扣变量
int iPerPurchaseDiscountPercent=0//输入一个稍后将更改为百分比的数字
int iFinalPurchaseDiscountPercent=0//输入一个稍后将更改为百分比的数字
浮动fPerPurchaseDiscountPercent=0//每件商品的折扣百分比值
浮动fFinalPurchaseDiscountPercent=0//最终计数的百分比值
浮动FPERPURCHASEDISCONTPRICE=0//将应用折扣的价格
浮动fFinalPurchaseDiscountPrice=0//将应用最终商店折扣的价格
//数学数组值
float-fItemPrice[100]={0}//商品价格
int iItemQuantity[100]={0}//该商品的数量
浮点fBundleCost[100]={0}//折扣前价格(fItemPrice[N]*fItemQuantity[N])
float fDiscountPerItem[100]={0}//每件商品的折扣是多少(fItemPrice[N]*iPerPurchaseAmount)
float fItemTotalDiscountRecieved[100]={0}//同一类型多个项目收到的总折扣(fDicountPerItem*IIItemQuantity)
浮动fDiscountPrice[100]={0}//所有折扣后的项目价格(fBundleCost-Fdiscountreceived)
//while循环的值
boolbstillshopping=true;
int iItemCount=0;
char cexit question='y';
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//-----------------------------------------------原型-----------------------------------------------
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//------------------------------------------------主回路------------------------------------------------
//---------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------
内部主(空)
{
printf(“欢迎来到Blacketts书店!\t\t\t\t\t\tPOS V2\n”);
//获取每项折扣的值
printf(“请输入每件商品的折扣价格:”);
flushall();
scanf(“%f”,&fPerPurchaseDiscountPrice);//取项目折扣的值
printf(“请输入在此价格下应用的百分比:”);
flushall();
scanf(“%d”,&iPerPurchaseDiscountPercent);//获取一个值,例如10,以后将其更改为.1,表示10%
fPerPurchaseDiscountPercent=iPerPurchaseDiscountPercent/100;//将int更改为浮点,并使其适用于百分比计算
//获取最终购买折扣的价值
printf(“请输入将应用于销售结束折扣的价格:”;
flushall();
scanf(“%f”,&fFinalPurchaseDiscountPrice);//取整个摘要的折扣值
printf(“请输入在此价格下应用的百分比:”);
flushall();
scanf(“%d”,&iFinalPurchaseDiscountPercent);//接受一个值,例如5,稍后将其更改为.05,表示5%
fFinalPurchaseDiscountPercent=iFinalPurchaseDiscountPercent/100;//将int更改为浮点,并使其适合百分比计算
//While循环获取值并将其输入到适当的位置
while(bStillShopping==true)
{
iItemCount=1;//计算购买的物品数量,0=1件。因此,物品的总数量必须等于iItemCount+1
printf(“\n请输入要购买的第一件商品的价格:”;//输入商品的价格
flushall();
scanf(“%.2f”,fItemPrice[iItemCount]);
printf(“请输入该项目的数量:”;//输入数量
flushall();
scanf(“%d”,iItemQuantity[iItemCount]);
printf(“\n是否要输入更多项目?(y/n):”;//要求继续
flushall();
scanf(“%c”和&cexit);
如果(cExitQuestion='n')
{
bStillShopping=false;//如果不想继续,请退出循环
}
其他的
{
iItemCount++;//如果继续递增项循环并请求更多变量
}
}
getch();
}    
当我在
iItemQuantity[iItemAmout]
输入数量时,程序将因未处理的异常而崩溃。我还对代码之间的print语句进行了一些调试,以查看它到达的位置,并输出我输入的变量和返回的值不匹配,我收到的只是
0.00

非常感谢您的帮助,我希望我不是在其他地方问一个已经回答过的问题。仍然不知道如何浏览网站


我知道代码目前没有做任何其他事情,但我不认为在第一个问题得到纠正之前继续下去有什么意义。

对数组元素也使用
scanf中的
&

像这样

scanf("%.2f", &fItemPrice[iItemCount]);

scanf("%d", &iItemQuantity[iItemCount]);

问题在于
scanfscanf("%.2f", fItemPrice[iItemCount]);
scanf("%.2f", &fItemPrice[iItemCount]);
scanf("%.2f", fItemPrice + iItemCount);