Ok so what im trying to do here is a receipt, program is supposed to ask how many clients, and how many diffrent products each client takes, then calculate sub-total before taxes, then total(with taxes). Ok so im using arrays and structures, my problem is at the moment of showing the information of said receipts on the screen it shows the products of the 2nd client only(if its 2 clients), if its 3 then only the products of the 3rd, etcCode:#include <stdio.h> #include <conio.h> static void forcefloat(float*p) { float f=*p; forcefloat(&f); } struct client { char client[30]; }; struct client data[30]; struct seller { char ne[30]; }; struct seller data2[30]; struct product { char np[30]; float pp; int cp; }; struct product data3[30]; struct store { char nt[30],fecha[20]; }; struct store data4[30]; struct cpp { int cpp;/*quantity of diffrent products*/ float stt,tt;/*counter for subtotal(stt) and total(tt)*/ }; struct cpp data5; void read(int); void show(int); void main() { int i; clrscr(); printf("\nHow many clients are going to be evaluated:"); scanf("%d",&i); read(i); show(i); getch(); } void read(int i) { int j,z=0,cpp; float st,sttt,t,tt=0,stt=0; clrscr(); for(j=0;j<i;j++) { printf("Insert name of the store: "); scanf(" %[^\n]",data4[j].nt); printf("\nInsert current date: "); scanf(" %[^\n]",data4[j].fecha); printf("\nInsert client name: "); scanf(" %[^\n]",data[j].client); printf("\nInsert seller name: "); scanf(" %[^\n]",data2[j].ne); printf("\nInsert the amount of diffrent products the client bought: "); scanf("%d",&data5.cpp); for(z=0;z<data5.cpp;z++) { printf("\nInsert name of product number %d: ",z+1); scanf(" %[^\n]",data3[z].np); printf("\nInsert the amount bought of said product: "); scanf("%d",&data3[z].cp); printf("\nInsert price of the product: "); scanf("%f",&data3[z].pp); st=(data3[z].cp*data3[z].pp);/*subtotal before tax*/ data5.stt=data5.stt+st; sttt=(0.15*st); t=(st+sttt);/*total after tax*/ data5.tt=data5.tt+t; } clrscr(); } } void show(int i) { int j,z; clrscr(); for(j=0;j<i;j++) { printf("\n\t\t\t\tStore %s",data4[j].nt); printf("\t\t\t%s",data4[j].fecha); printf("\n\nClient %s",data[j].client); printf("\nSeller %s",data2[j].ne); for(z=0;z<data5.cpp;z++) { printf("\n\nProduct %s",data3[z].np); printf("\nQuantity of product: %d",data3[z].cp); printf("\nPrice of product: %.2f",data3[z].pp); } printf("\n\nSub-Total: %.2f",data5.stt); printf("\nIVA: 15 Percent"); printf("\n\nTotal: %.2f",data5.tt); } }
So for example it would show the receipt for the 1st client just fine, it prints name, salesmen, date, etc but sadly it shows the products, subtotal and totals of the 2nd client i know my for cycle or my array is somehow messed up. Any ideas how to fix this? Any help would be appreciated.
Sorry for some of the code not being in english im latin