| | |
C help calculate grand total
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: May 2005
Posts: 3
Reputation:
Solved Threads: 0
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....
<< moderator edit: added [code][/code] tags >>
thx...
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....
C Syntax (Toggle Plain Text)
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); }
thx...
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
•
•
Join Date: May 2005
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
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....
![]() |
Similar Threads
- The switch statement (C++)
- How to calculate total free memory (C)
- Using Loops to calculate totals in C Program (C)
Other Threads in the C Forum
- Previous Thread: Read an Integer from the User, Part 1
- Next Thread: having problems to complete implement a simple calculator program in c
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue number oddnumber odf opensource overwrite owf pdf performance pointer posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket socketprograming spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi






