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;
}

is this program correct????????

Does it give you the correct answer?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.