gpt4 book ai didi

c - 循环不起作用

转载 作者:行者123 更新时间:2023-11-30 17:38:49 25 4
gpt4 key购买 nike

当出现“您想输入另一个备件吗”参数时,我无法输入值。它自动从头开始循环。当用户输入 y 时,我真的需要定义它吗?

   void spareParts()
{
char date[11];
char Part[ENTRIES];
char Value[ENTRIES];
int i;
char choice;

for(i=0; i<100; i++)
{
printf("Spare parts value calculator!\n");
printf("--------------------------------------------------\n");
printf("Date (dd/mm/year):");
scanf("%c", date);


printf("Part No:");
scanf("%s", Part);


printf("Value:");
scanf("%s", Value);

printf("Would you like to enter another spare part:");
scanf("%c", &choice);

if(choice=='n')
{
/*double total=0;
total += Value[i];
void printResults(double total, char date);*/
break;
}
}
}

void printResults(double total, char date)
{
printf("The Wheeler Autoparts Company\n");
printf("----------------------------------------------\n");
printf("Inventory details\n");
printf("Date %c\n", date);
printf("------------------------------------------\n");
printf("%.2s%.2s\n", "Part" , "Value");
printf("--------------------------------------\n");
printf("Total: %.2f\n", total);
}


int main(void)
{

spareParts();
return 0;

}

最佳答案

改变

scanf("%c", date);

scanf("%s", date);

关于c - 循环不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22024982/

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