gpt4 book ai didi

c - For 循环在不应该的情况下向后打印,有解决方案的输入吗?

转载 作者:行者123 更新时间:2023-11-30 19:01:34 25 4
gpt4 key购买 nike

我正在尝试为最终项目增量打印客户编号和销售数组“1-4”和“1000-4000”。相反,它打印出“4-1”和“4000-1000”。关于我做错了什么有什么意见吗?

    printf("How many customers do you want to track?\n");
scanf("%d", &ctracked);

while((ctracked!=0)&&(ctracked--))
{
printf("Enter customer number. ");
scanf("%d", &cnumber[ctracked]);
printf("Enter the sales for the customer ");
scanf("%d", &csales[ctracked]);
}

printf("Sales for the Customer\nCustomer Customer\n");
printf("Number Sales\n");

for(counter=0; counter<ALLOWED_RANGE; counter++)
{
printf("%d %d\n", cnumber[counter], csales[counter]);
}

totalsales = csales[0] + csales[1] + csales[2] + csales[3];
avgsales = totalsales / (float)4.0;
printf("\nTotal sales are $%d\n", totalsales);
printf("Average sales per customer is $%.2f", avgsales);
}

最佳答案

只需使用以下代码更改 while 循环“while((ctracked!=0)&&(ctracked--))”即可。

for(counter=0;counter<ctracked;counter++)
{
printf("Enter customer number. ");
scanf("%d", &cnumber[counter]);
printf("Enter the sales for the customer ");
scanf("%d", &csales[counter]);
}

关于c - For 循环在不应该的情况下向后打印,有解决方案的输入吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57619023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com