Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. int add_trans_to_balance(double , double);
  5.  
  6. int main()
  7. {
  8.     int account, matchfound=0;     /* account number */
  9.     char date[ 30 ]; /* account Date */
  10.     double balance, saleamount, total=0, temp;  /* account SaleAmount */
  11.    
  12.     int transaccount,count=1, count1=0;
  13.     char name [ 30 ];
  14.    
  15.    
  16.  
  17.     FILE *cfPtr;     /* cfPtr = clients.dat file pointer */
  18.     FILE *cfPtr1;
  19.     FILE *cfPtr2;    /* cfPtr2 = new client file */
  20.          
  21.     cfPtr2 = fopen( "newclient.dat", "w" );
  22.    
  23.     /* fopen opens file; exits program if file cannot be opened */
  24.     if ( ( cfPtr = fopen( "clients.dat", "r" ) ) == NULL ) {
  25.         printf( "clients could not be opened\n" );
  26.         fflush(stdin);
  27.     } /* end if */
  28.     else if( ( cfPtr1 = fopen( "transactions.dat", "r" ) ) == NULL){
  29.         printf( "trans could not be opened\n" );
  30.         fflush(stdin);
  31.     }
  32.     else { /* read account, date and SaleAmount from file */
  33.         fscanf( cfPtr, "%d%s%lf", &account, &name, &balance );
  34.         fflush(stdin);
  35.        
  36.         fscanf( cfPtr1, "%d%s%lf", &transaccount, &date, &saleamount );
  37.         fflush(stdin);
  38.    
  39.        
  40.         while( !feof(cfPtr1))
  41.         {  
  42.            
  43.             while( !feof(cfPtr) && matchfound==0 )
  44.            {  
  45.                
  46.                              
  47.                if(account == transaccount)
  48.                {
  49.                    matchfound=1;
  50.                     total=0;
  51.                     count1++;
  52.                    
  53.                     temp = add_trans_to_balance(saleamount, balance);
  54.                     total = total + temp;
  55.                     balance = total;
  56.  
  57.                    
  58.                     printf("%d %s %s %.2lf\n", account, name, date, total);
  59.                    
  60.                    
  61.                 }
  62.                 else
  63.                 {
  64.                     count++;
  65.                     fscanf( cfPtr, "%d%s%lf", &account, &name, &balance );
  66.                     fflush(stdin);
  67.                 }
  68.                
  69.                
  70.                
  71.             }
  72.            
  73.             fprintf( cfPtr2, "%d %s %.2lf\n", account, name, total );
  74.             fscanf( cfPtr1, "%d%s%lf", &transaccount, &date, &saleamount );
  75.             printf("a\n%d\n%d\n",count,count1);
  76.             fflush(stdin);
  77.             matchfound=0;
  78.             count1=0;
  79.            
  80.             if(transaccount != account)
  81.             {
  82.                 total=0;
  83.             }
  84.         }
  85.     }
  86. fclose( cfPtr2 );
  87. getch();
  88. }
  89.                    
  90. int add_trans_to_balance(double trans, double balance)
  91. {
  92.     double total;
  93.    
  94.     total = trans + balance;
  95.    
  96.     return total;
  97.    
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement