本文介绍了帮助此CHW问题...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写程序以读取库存文件并创建库存报告.该报告将包含零件号,价格,现有数量,重新订购点,最小订购量和订购数量.当手头数量低于重新订购点时,将计算订购数量.计算方法为再订购点和最小订购量之和减去现有数量.

每当我运行程序时,我得到的只是
读取数据时出错
报告结束"

我究竟做错了什么???救命!

"

Im trying to write a program to read an inventory file and create an inventory report. The report is to contain the part number, price, quantity on hand, reorder point, minimum order, and order amount. The order amount is calculated when the quantity on hand falls below the reorder point. It is calculated as the sum of the reorder point and the minimum order minus the quantity on hand.

Whenever I run the program though, all I get is
"Error reading data
End of Report"

What am I doing wrong??? Help!

"

#include <stdio.h>
#include <ctype.h>
int getData (FILE *spInData,
             int *partNo, int *price,
             int *quant, int *reorder, int *minimum);
void calcAmt (int *orderAmt, int quant, int minimum, int reorder);
int writeReport (FILE *spReport, int partNo, int price, int quant, int reorder,
                 int minimum, int orderAmt);

int main (void)
{
//  Local Declarations
    int partNo;
    int price;
    int quant;
    int reorder;
    int minimum;
    int orderAmt;
    FILE* spInData;
    FILE* spReport;
//  Statements
    if (!(spInData = fopen("INVENTORYDATA.TXT", "r")))
       {
        printf("Error opening INVENTORYDATA.TXT for reading");
        return 100;
       } // if file open error
    if (!(spReport = fopen("INVENTORYREPORT.TXT", "w")))
       {
        printf("Error opening inventory report\n");
        return 102;
       }
    while (getData(spInData, &partNo, &price, &quant, &reorder, &minimum))
       {
        calcAmt (&orderAmt, quant, minimum, reorder);
        writeReport (spReport, partNo, price, quant, reorder, minimum, orderAmt);
       } // while
    fclose(spInData);
    fclose (spReport);
    printf("End of Report\n");

    return 0;
}   // main
int getData (FILE *spInData,
             int *partNo, int *price,
             int *quant, int *reorder, int *minimum)
{
    int ioResult;
    ioResult = fscanf(spInData, "%d%d%d%d%d", partNo,
                      price, quant, reorder, minimum);
    if (ioResult == EOF)
        return 0;
    else if (ioResult !=5)
    {
        printf("\aError reading data\n");
    return 0;
    }
    else
        return 1;
}
void calcAmt (int *orderAmt, int quant, int minimum, int reorder)
{
    int ioResult;
    while( ioResult != EOF)
    {
        if(quant<reorder)
        {
            *orderAmt = (reorder+minimum)/quant;
            return;
        }
        else
        {
            return;
        }
    }
}
int writeReport (FILE *spReport, int partNo, int price, int quant, int reorder,
                 int minimum, int orderAmt)
{
    printf("Part No.  Price    Quantity  Reorder Point Minimum Order\n");
    fprintf(spReport, "%04d %d %d %d %d %d\n", partNo, price, quant, reorder, minimum, orderAmt);
    return 0;
}

推荐答案


这篇关于帮助此CHW问题...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 17:40