The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled C Code
Posted by: blah | October 2, 2010 @ 7:19am
C Code
[
Download
]
#include <ctype.h> #include <stdio.h> #define MAX_TRANSACTIONS 10 struct items { double price; int quantity; double markup; double total_price; int total_sales; }; void getnum(char *, const char *, void *); struct items costs[MAX_TRANSACTIONS]; int trans; double profit; int main() { struct items *p; char buffer[512]; char prompt; do { fputs("\n\tBUSINESS CALC SOFTWARE\n\n\n\tHow many transactions do you want? : ", stdout); do { getnum(buffer, "%d", &trans); if(trans > MAX_TRANSACTIONS) { fputs("\n\t\t(No transactions beyond 10)\n\n\tEnter transactions : ", stdout); continue; } break; } while(1); profit = 0; for(p = costs; p < &costs[trans]; ++p) { fputs("\n\n\tEnter item price : ", stdout); getnum(buffer, "%lf", &p->price); fputs("\n\tEnter item quantity : ", stdout); getnum(buffer, "%d", &p->quantity); fputs("\n\tEnter markup : ", stdout); getnum(buffer, "%lf", &p->markup); p->total_price = (p->price + p->markup) * p->quantity; p->total_sales += p->total_price; p->markup *= p->quantity; printf("\n\n\tTotal item price : %.2lf\n\n\n\t", p->total_price); profit += p->markup; } printf("\n\tTotal sales\t: %d", p->total_sales); printf("\n\tProfit\t\t: %.2lf\n\n", profit); fputs("\n\nDo you want another transaction? <y,n> ", stdout); getnum(buffer, "%c", &prompt); prompt = (isupper(prompt) ? tolower(prompt) : prompt); } while(prompt == 'y'); return 0; } void getnum(char *buff, const char *format, void *ptr) { fgets(buff, sizeof buff, stdin); sscanf(buff, format, ptr); }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.40 / 8
52 Votes
http://codebin.yi.org/873
page generated in 0.00 seconds