杂货店的库存

时间:2013-09-23 00:45:46

标签: c

我写了一个程序来跟踪杂货店的库存。但在我的代码中我想打印一个值。价值是(单位数)*(单价)。但不知怎的,我得到了我的程序中的垃圾值。你能帮我吗?

#include<stdio.h>
#include<conio.h>
#define MAX 5
int printinventory(int , int unit[] , float price[]);
int main()
{
    int item[MAX],unit[MAX],x,i;
    float price[MAX];
    printf("Please enter how many category items (up to 5) : ");
    scanf("%d",&x);
    for(i=0;i<x;i++)
    {
    printf("\nPlease enter Number of Units #%d : ",i+1);
    scanf(" %d",&unit[i]);
    printf("\nPlease enter the Unit Price #%d : ",i+1);
    scanf(" %f",&price[i]);
    }
    printinventory(x , unit , price);
    getch();
}

int printinventory (int  y, int unit[] , float price[])
{
    int i,j=0;
    float value[MAX];
    for(i=0;i<y;i++);
    {
        value[i] = (unit[i] * price[i]);
    }
    system("cls");
    printf("Item     Number of Units   Unit Price    Value ");
    printf("\n\n------------------------------------------------");
    for(i=1;i<=y;i++)
    {
        printf("\n%d",i);
        printf("\t  %d",unit[j]);
        printf("\t\t    $%.2f",price[j]);
        printf("\t$%.2f",value[j]);
        j++;
    }
    printf("\n\n------------------------------------------------");
    printf("\n\t\t\t\tTotal   $   ");
    getch();
}

1 个答案:

答案 0 :(得分:5)

问题似乎是你错误地在for个循环的末尾包含了分号:

    for(i=0;i<y;i++);