943,940 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 1931
  • C RSS
May 20th, 2005
0

C help calculate grand total

Expand Post »
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...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dejaz is offline Offline
3 posts
since May 2005
May 20th, 2005
0

Re: C help calculate grand total

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.
Reputation Points: 35
Solved Threads: 3
Posting Whiz in Training
Dogtree is offline Offline
232 posts
since May 2005
May 20th, 2005
0

Re: C help calculate grand total

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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dejaz is offline Offline
3 posts
since May 2005
May 20th, 2005
0

Re: C help calculate grand total

I'd imagine something like...
double prof = 0;
// ...
while(/*...*/)
{
   double p = profits(ssg.prodprice, ssg.prodcost, ssg.prodquan);
   // ...
   prof += p;
}
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
May 20th, 2005
0

Re: C help calculate grand total

Quote 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....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dejaz is offline Offline
3 posts
since May 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Read an Integer from the User, Part 1
Next Thread in C Forum Timeline: having problems to complete implement a simple calculator program in c





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC