Click here to Skip to main content
15,940,550 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I was wondering if someone can help me with my project.

I need help with the order amount. I was going to use a if else statement, but I'm not sure how to start it.


Project information:
Write a program that reads a file and create a report. The report will 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 reorder point.

It is calculated as the sum of the reorder point and the minimum order less the quantity on hand.

Provide a report heading, captions for each column, and an end of report message at the end of the report.

Print the part number with leading zeros.

My code:
C#
#include "stdafx.h"
#include "stdlib.h"
int main(void)
{
/* num = part no., point= reorder point, order= min order */
FILE* sp1;
int num;
int quantity;
int point;
int order;
float price;
sp1 = fopen("c:\\inventory.txt", "r");
if (!sp1)
{
    printf("Error: Can't open file\a\n");
    exit (101);
}

printf("                         Inventory Report          \n");
printf("================================================================\n");
printf("Part No.  Price  Quantity  Reorder Point  Min Order  Order Amount\n\n");


 while((fscanf(sp1,"%4d%5f%2d%2d%2d",&num, &price, &quantity, &point, &order)) ==5)
{
    printf("%04d     %2.2f     %2d          %2d           %2d\n",num, price, quantity, point, order);
 }
    printf("=================================================================\n\n\n");
    printf("            End of Report                       \n");



return 0;
}
Posted

1 solution

Within your while loop and before printf (order_amount should be defined at the beginning just like rest of variables but must be reset to zero before if statement):
order_amount=0;
if(quantity < order_point)
{
 order_amount = order_point+min_order-quantity;
}


OR
if(quantity < order_point)
 order_amount = order_point+min_order-quantity;
else order_amount = 0;


...added a different style as well...
 
Share this answer
 
v3
Comments
jessica smith1 3-Apr-11 1:09am    
That worked great! Thank you!
Albert Holguin 3-Apr-11 1:12am    
no prob :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900