循环不起作用

时间:2014-02-25 20:06:07

标签: c loops

当“你想要输入另一个备件”参数出现时,我无法输入值。它从头开始自动启动循环。 当用户输入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;

}

1 个答案:

答案 0 :(得分:0)

更改

scanf("%c", date);

scanf("%s", date);