Snippet
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX 99
int main(void) {
struct {
char item[MAX];
float cost;
int amount;
} x[MAX];
int i=1,t2=0,ts=0,c=0;
float total=0;
char store[MAX],buffer[MAX],ch;
FILE *printer;
printf("\nEnter Store Name:");
while(ch!='\n') {
if(c>=98){
exit(1);
}
ch=getc(stdin);
store[c]=ch;
c++;
}
c=0;
ch='\0';
while (i<MAX) {
printf("\nSale for %s", store );
while(ch!='\n') {
if(c>=98){
exit(1);
}
ch=getc(stdin);
buffer[c]=ch;
c++;
}
for(c=0;c<MAX;c++) {
if(buffer[c]!='\n')x[i].item[c]=buffer[c];
}
c=0;
ch='\0';
while(ch!='\n') {
if(c>=98){
exit(1);
}
ch=getc(stdin);
buffer[c]=ch;
c++;
}
x[i].cost=atof(buffer);
c=0;
ch='\0';
while(ch!='\n') {
if(c>=98){
exit(1);
}
ch=getc(stdin);
buffer[c]=ch;
c++;
}
x[i].amount=atoi(buffer);
c=0;
ch='\0';
if(x[i].amount==99) {
//i--;
if ((printer = fopen("LPT1","wb+")) == NULL) {
printf("Error trying to connect to printer");
}
printf("\n\nSales Summery for %s", store );
printf("\nTotal Transactions: %i\nItems sold: %i\nTotal profit: $%.2f", ts, t2, total );
fprintf(printer,"\n\r\n\rSales Summery for %s", store);
fprintf(printer,"\n\rTotal Transactions: %i\n\rItems sold: %i\n\rTotal profit: $%.2f", ts, t2, total);
i=1;
while(i<=ts) {
fprintf(printer,"\n\rSale #%i: %s\n\r Quantity: %i\n\r Total Sale: $%.2f", i, x[i].item, x[i].amount, x[i].cost*x[i].amount);
printf("\nSale #%i: %s\n Quantity: %i\n Total Sale: $%.2f", i, x [i ]. item, x [i ]. amount, x [i ]. cost*x [i ]. amount);
i++;
}
exit(0); /* clean smooth exit! End of day, relax */
if(printer)fclose(printer);
}
if((printer=fopen("LPT1","wb+"))==NULL){
printf("Error trying to connect to printer");
}
fprintf(printer,"\n\r%d of %s sold for $%.2f\n\r\n\r", x[i].amount, x[i].item, x[i].cost*x[i].amount);
printf("\n%d of %s sold for $%.2f\n\n", x [i ]. amount, x [i ]. item, x [i ]. cost*x [i ]. amount);
if(printer)fclose(printer);
t2=x[i].amount + t2;
total=total+(x[i].cost*x[i].amount);
ts=i;
i++;
}
if(printer) fclose (printer);
return 0;
}
Copy & Paste
|