Hi,everybody!
I definetely don't know what my program wants from me!
I'll appreciate if somebody helps we to fine what is wrong.
Thank you very much!
This program reads in two file,one of them has masters records(customid,name,balance);another file has transactions for each customer with payment("P") or new order("O") records.
The program is reading in two structures,calculate Balance Due and prints the invoice for each customer.
The compile errors :
87: passing `char' to argument 1 of `findtotal(char *, int)' lacks a cast
102: parse error before `{'
106: `transitem' undeclared (first use this function)
`transitemqty' undeclared (first use this function)
107: `return' with a value, in function returning void
In function `void printinvoice(customer *, int, transaction *, int *)':
127: ANSI C++ forbids comparison between pointer and integer
THIS IS THE CODE:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct custname{
char last[10];
char first[10];
};
struct customer{
int custid;
struct custname name;
float prevbalance;
};
struct transaction{
char typepmt;
int custid;
int transid;
char item[20];
int itemqty;
float totalamt;
};
/*struct newcustomer{
int custid;
struct custname name;
float newbalance;
};*/
void readdata(struct customer *,int *,struct transaction *,int *);
float findtotal(char [20] ,int ); /*we'll call it inside of readdata*/
void printinvoice(struct customer *,int ,struct transaction *,int *);
main()
{
struct customer cust[20];
struct transaction trans[60];
//struct newcustomer newcust[100];
int num,num1;
// float findtotal(transaction.);
readdata(cust,&num,trans,&num1);
printinvoice(cust,num,trans,&num1);
}
void readdata(struct customer *cust, int *num,struct transaction *trans,int *num1)
{
char *instring;
char buffer[150],buffer1[300];
FILE *master,*transact,*invoice;
int count,count1;
float transamt;
master= fopen("master.txt","r");
if (master == NULL){
fprintf(stderr,"Error opening master input file\n");
exit(1);
}
transact = fopen("transact.txt", "r");
if (transact == NULL){
fprintf(stderr,"Error opening input transaction file\n");
exit(1);
}
count = 0;
count1 = 0;
while((instring=fgets( buffer,150,master))!=NULL){
if(cust[count].custid==cust[count+1].custid){
fprintf(stderr,"Customer ID is duplicate!\n");
exit(1);
}
count++;
*num= count;
while(fscanf(transact,"%d",&trans[count1].transid) != EOF){
fscanf(transact,"%s",trans[count1].typepmt);
fscanf(transact,"%5f",&trans[count1].custid);
if(&trans[count1].typepmt=="O"){
fscanf(transact,"%s",trans[count1].item[20]);
fscanf(transact,"%d",&trans[count1].itemqty);
trans[count1].totalamt=findtotal(trans[count1].item[20],trans[count1].itemqty);
/* fscanf(transact,"%$5.2f",&trans[count1].totalamt=findtotal(trans[count1].item,trans[count1].itemqty)); */
}
else{
fscanf(transact,"%$5.2f",&trans[count1].totalamt);
}
count1++;
}
*num1 = count1;
fclose(master);
fclose(transact);
return ;
}
float findtotal(char transitem[20],int transitemqty)
{
float total;
float total=0.00;
total= (float)transitem[20]*transitemqty;
return total;
}
void printinvoice(struct customer *cust, int num,struct transaction *trans, int *num1)
{
FILE *invoice;
int count,count1;
float balancedue;
invoice=fopen("custominvoice.txt","w");
if (invoice==NULL){
fprintf(stderr,"Error opening input transaction file\n");
exit(1);
}
fprintf(invoice,"\t\tCustomer invoice\n\n");
for(count = 0;count < num;count++){
fprintf(invoice,"Customer Name \t\tCustomer Account Number");
fprintf(invoice,"s% ",cust[count].name.last);
fprintf(invoice,"s%\t ",cust[count].name.first);
fprintf(invoice,"d%\t\n\n ",cust[count].custid);
fprintf(invoice,"Previous Balance $8.2f%\t \n\n\n",cust[count].prevbalance);
if(trans[count1].typepmt=="O"){
fprintf(invoice,"%d\t",trans[count1].transid);
fprintf(invoice,"%s\t",trans[count1].item[20]);
fprintf(invoice,"%$5.2f\t\n\n",trans[count1].totalamt);
balancedue= cust[count].prevbalance + trans[count1].totalamt;
fprintf(invoice,"Balance Due $8.2f%\t \n\n",balancedue);
}
else{
fprintf(invoice,"payment\t");
fprintf(invoice,"%$5.2f\t",trans[count1].totalamt);
balancedue= cust[count].prevbalance - trans[count1].totalamt;
fprintf(invoice,"Balance Due $8.2f%\t \n\n",balancedue);
}
count1++;
}
*num1 = count1;
}