Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- int add_trans_to_balance(double , double);
- int main()
- {
- int account, matchfound=0; /* account number */
- char date[ 30 ]; /* account Date */
- double balance, saleamount, total=0, temp; /* account SaleAmount */
- int transaccount,count=1, count1=0;
- char name [ 30 ];
- FILE *cfPtr; /* cfPtr = clients.dat file pointer */
- FILE *cfPtr1;
- FILE *cfPtr2; /* cfPtr2 = new client file */
- cfPtr2 = fopen( "newclient.dat", "w" );
- /* fopen opens file; exits program if file cannot be opened */
- if ( ( cfPtr = fopen( "clients.dat", "r" ) ) == NULL ) {
- printf( "clients could not be opened\n" );
- fflush(stdin);
- } /* end if */
- else if( ( cfPtr1 = fopen( "transactions.dat", "r" ) ) == NULL){
- printf( "trans could not be opened\n" );
- fflush(stdin);
- }
- else { /* read account, date and SaleAmount from file */
- fscanf( cfPtr, "%d%s%lf", &account, &name, &balance );
- fflush(stdin);
- fscanf( cfPtr1, "%d%s%lf", &transaccount, &date, &saleamount );
- fflush(stdin);
- while( !feof(cfPtr1))
- {
- while( !feof(cfPtr) && matchfound==0 )
- {
- if(account == transaccount)
- {
- matchfound=1;
- total=0;
- count1++;
- temp = add_trans_to_balance(saleamount, balance);
- total = total + temp;
- balance = total;
- printf("%d %s %s %.2lf\n", account, name, date, total);
- }
- else
- {
- count++;
- fscanf( cfPtr, "%d%s%lf", &account, &name, &balance );
- fflush(stdin);
- }
- }
- fprintf( cfPtr2, "%d %s %.2lf\n", account, name, total );
- fscanf( cfPtr1, "%d%s%lf", &transaccount, &date, &saleamount );
- printf("a\n%d\n%d\n",count,count1);
- fflush(stdin);
- matchfound=0;
- count1=0;
- if(transaccount != account)
- {
- total=0;
- }
- }
- }
- fclose( cfPtr2 );
- getch();
- }
- int add_trans_to_balance(double trans, double balance)
- {
- double total;
- total = trans + balance;
- return total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement