任何人都可以帮我处理我的代码,如果我的订单超出可用库存或者不是
,我在3. Order
验证订单时会遇到问题
int main(void){
int choice = 0;
int year = 1, i, com;
int storage[99] = {0};
for (;;) {
clrscr();
printf("Year %d\n\n", year);
printf("1. Import\n");
printf("2. Storage\n");
printf("3. Order\n");
printf("\nchoice: ");
scanf("%d", &choice);
if (choice == 1){ // import
clrscr();
printf("Enter sets of computer's imported: ");
scanf("%d", &storage[year]);
year++;
}
if (choice == 2){ // storage
clrscr();
printf("Year sets\n");
for (i = 1; i < year; i++){
printf("%2d %4d\n", i, storage[i]);
}
getch();
}
if(choice == 3){ //order
printf("Enter Sets of Computer ordered: ");
scanf("%d", &com);
for (i = 0; com && i < 99; i++){
if (com <= storage[i]){
storage[i] = storage[i] - com;
com = 0;
}
if (com > storage[i]){
printf("Sorry we have No enough Stocks !");
}
if (storage[i] <= com){
com = com - storage[i];
storage[i] = 0;
}
}
}
}
}
例如:
我在choice 1. Import
在Year 1
我导入500
台计算机
在Year 2
i导入1000
台计算机
在Year 3
i导入800
台计算机
查看我的2. Storage
时会显示此内容
Year sets
1 500
2 1000
3 800
我的2. Storage
现在在3. Order
我输入的计算机集合为5000
。
5000
超出了我2. Storage
中的库存,因此我预计订单将无法继续显示Sorry we have No enough Stocks !
但是再次查看2. Storage
时会显示错误的输出
Year sets
1 0
2 0
3 0
你可以看到它现在是空的