hi guys,

i am stuck... we have to show wats in a file.... then at the end show the grand total of the Profits .. heres the report func....

void report()
{
	struct Prods ssg;
	
	double prof;
	
	FILE *f;
	f = fopen("data.dat","rb");

		printf("\n\n\n==============================================================================\n");
		printf("Prod#   Type   Description	    Qty      Cost        Price        Profit\n");
		printf("==============================================================================\n");

	while(fread(&ssg,sizeof(ssg),1,f))
	{

		printf("\n%-9d%-7d%-21.18s%-2d%13.2lf%13.2lf%13.2lf\n", 
						ssg.prodnum, ssg.prodt, ssg.desc, ssg.prodquan, ssg.prodcost, ssg.prodprice, profits(ssg.prodprice, ssg.prodcost, ssg.prodquan));

	
	}
		printf("\n==============================================================================\n");

		//print grand total of PROFIT

		printf("%d",prof);

	fclose(f);

}

<< moderator edit: added [code][/code] tags >>


thx...

How does that function not work? There are a few iffy parts, like not checking fopen for success and not considering that fread can return a non-zero failure code, but there are no obvious errors that I can see this early in the morning. ;)

thx Dogtree for the reply.... i'll fix the probs u mentioned... func i mentioned works and displays everything .... but the main concern is that i have to add all the profits and at the end show the grand total of the profits... and i dont know how to do that....

thx...

I'd imagine something like...

double prof = 0;
// ...
while(/*...*/)
{
   double p = profits(ssg.prodprice, ssg.prodcost, ssg.prodquan);
   // ...
   prof += p;
}

I'd imagine something like...

double prof = 0;
// ...
while(/*...*/)
{
   double p = profits(ssg.prodprice, ssg.prodcost, ssg.prodquan);
   // ...
   prof += p;
}

THANKS man... what u said worked perfectly.... ;)

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.