C help calculate grand total

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: May 2005
Posts: 3
Reputation: dejaz is an unknown quantity at this point 
Solved Threads: 0
dejaz dejaz is offline Offline
Newbie Poster

C help calculate grand total

 
0
  #1
May 20th, 2005
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....

  1. void report()
  2. {
  3. struct Prods ssg;
  4.  
  5. double prof;
  6.  
  7. FILE *f;
  8. f = fopen("data.dat","rb");
  9.  
  10. printf("\n\n\n==============================================================================\n");
  11. printf("Prod# Type Description Qty Cost Price Profit\n");
  12. printf("==============================================================================\n");
  13.  
  14. while(fread(&ssg,sizeof(ssg),1,f))
  15. {
  16.  
  17. printf("\n%-9d%-7d%-21.18s%-2d%13.2lf%13.2lf%13.2lf\n",
  18. ssg.prodnum, ssg.prodt, ssg.desc, ssg.prodquan, ssg.prodcost, ssg.prodprice, profits(ssg.prodprice, ssg.prodcost, ssg.prodquan));
  19.  
  20.  
  21. }
  22. printf("\n==============================================================================\n");
  23.  
  24. //print grand total of PROFIT
  25.  
  26. printf("%d",prof);
  27.  
  28. fclose(f);
  29.  
  30. }
<< moderator edit: added [code][/code] tags >>


thx...
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: C help calculate grand total

 
0
  #2
May 20th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 3
Reputation: dejaz is an unknown quantity at this point 
Solved Threads: 0
dejaz dejaz is offline Offline
Newbie Poster

Re: C help calculate grand total

 
0
  #3
May 20th, 2005
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...
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,450
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 250
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: C help calculate grand total

 
0
  #4
May 20th, 2005
I'd imagine something like...
double prof = 0;
// ...
while(/*...*/)
{
   double p = profits(ssg.prodprice, ssg.prodcost, ssg.prodquan);
   // ...
   prof += p;
}
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 3
Reputation: dejaz is an unknown quantity at this point 
Solved Threads: 0
dejaz dejaz is offline Offline
Newbie Poster

Re: C help calculate grand total

 
0
  #5
May 20th, 2005
Originally Posted by Dave Sinkula
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....
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC