0

how do i store the data from the partData file and find if the order was successful??????
is this program correct????????

#include <stdio.h>
#include <stdlib.h>


#define MaxWordSize 1000

        /*Part Number = PartNume
        Selling Price = SP
        Quantity in stock = QtyInStock
        Order Number = OrderNum
        Quantity requested = QtyRequested
        partData (file) = pd
        orders (file) = ord
        report (file) = rpt */


int binarySearch(int PartNum, double SP[], int QtyInStock[], int size){
       int lo = 0; int hi = size - 1; int mid;
       while(lo <=hi){
                mid = (lo + hi)/2;
                if(QtyInStock[mid] == PartNum) return 1;
                if(QtyInStock[mid] < PartNum) hi = mid - 1;
                else
                     lo = mid + 1;
                     return 0;
                     }
                     }


int orders(int PartNum, double SP[], int QtyInStock[], int size){
    int count = 0;
    for(int x = 0; x < size; x++){
            if(binarySearch(int PartNum, double SP[], int QtyInStock[], int size) == 1)
            count = count + 1;
            }
            return count;
            }


int main(){

    FILE * pd = fopen("partData.txt", "r"); 
    FILE * ord = fopen("orders.txt","r");
    FILE * rpt = fopen("report.txt", "w");

    int PartNum;
    int QtyInStock;
    double SP;  
    int OrderNum, count = 0;
    int QtyRequested;
    char myString [MaxWordSize];
    double InvoiceTotal = 0, TotalNumOfOrders = 0;
    int size = 20;



    fgets (myString, 1000, pd); 
    fgets (myString, 1000, ord);

    fscanf (pd, "%d", &PartNum);

    while (PartNum != 0) {
          fscanf (pd, "%lf", &SP);
          fscanf (pd, "%d", &QtyInStock);

          fscanf (pd, "%d", &PartNum);
          } 

    fscanf (ord, "%d", &OrderNum);

    while(OrderNum != 0){
          fscanf (ord, "%d", &PartNum);
          fscanf (ord, "%d", &QtyRequested);

          count = count + 1;
          TotalNumOfOrders = TotalNumOfOrders + count;
          InvoiceTotal = SP * QtyRequested;
          count = 0;
          QtyInStock = QtyInStock - QtyRequested;

    fprintf(rpt, "OrderNum: %d \t\t PartNum: %d \t\t QtyRequested: %d \t\t InvoiceTotal: $%4.2f \t\t \n", OrderNum,PartNum,QtyRequested,InvoiceTotal);

    fscanf (ord, "%d", &OrderNum);
}
    fprintf (rpt, "Total number of orders fulfilled is %d \n", TotalNumOfOrders); 
    fprintf (rpt, "Total number of orders not fulfilled is %d", TotalNumOfOrders);

    printf ("\n\n");


     fclose(pd); 
     fclose(ord);
     fclose(rpt);

system("pause");
return 0;
}

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by WaltP
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.