Mrm2299

Balance

May 11th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6. const int maxaccounts = 10;
  7. unsigned accountnumber [maxaccounts];
  8. double balance[maxaccounts];
  9. void process (unsigned &accountnumber,double &balance);
  10. void init (unsigned &accountnumber, double &balance);
  11.  
  12. main()
  13.  
  14. {
  15.     int noaccounts = 0;
  16.     while (noaccounts < maxaccounts)
  17.    
  18.     {
  19.         char transactiontype;
  20.         cout << "ENTER C TO CONTINUE OR X TO EXIT ";
  21.         cin >> transactiontype;
  22.        
  23.         if (transactiontype=='x' || transactiontype== 'x')
  24.        
  25.         {
  26.             break;
  27.         }
  28.        
  29.         init (accountnumber [maxaccounts],balance [maxaccounts]);
  30.         process (accountnumber[maxaccounts], balance [maxaccounts]);
  31.         noaccounts++;
  32.     }
  33.    
  34.     double total = 0;
  35.     cout << "ACCOUNT INFORMATION: \n";
  36.     for (int i = 0; i<noaccounts; i++)
  37.    
  38.     {
  39.         cout << "BALANCE FOR ACCOUNT"
  40.         << accountnumber [i]
  41.         << "="
  42.         << balance[i]<<"\n";
  43.         total = balance[i];
  44.     }
  45.    
  46.     cout <<"BALANCE FOR ALL ACCOUNTS= "
  47.     << total << "\n";
  48.     getch();
  49.    
  50.     }  
  51.    
  52.    
  53.     void init (unsigned &accountnumber,double&balance)
  54.    
  55.     {
  56.         cout <<" ENTER ACCOUNT NUMBER: ";
  57.         cin >> accountnumber;
  58.         balance = 0.0;
  59.     }
  60.    
  61.     void process (unsigned &accountnumber,double & balance)
  62.    
  63.     {
  64.         cout << "ENTER POSITIVE NUMBER FOR DEPOSIT  \n"
  65.         << "NEGATIVE FOR WITHDRAWAL \n ";
  66.         double transaction;
  67.         do {
  68.             cout << ":";
  69.             cin >> transaction;
  70.             if (transaction > 0)
  71.             {
  72.                 balance += transaction;
  73.                
  74.             }
  75.            
  76.             if (transaction < 0)
  77.             {
  78.                 transaction=-transaction;
  79.                 if (balance < transaction)
  80.                
  81.                 {
  82.                     cout << "INSUFFICIENT FUNDS FOR BALANCE"
  83.                     << balance
  84.                     << "CHECK"
  85.                     << transaction << "\n";
  86.                 }
  87.                 else
  88.                 {
  89.                     balance = transaction;
  90.                 }
  91.                
  92.                
  93.             }
  94.            
  95.         }while(transaction!=0);
  96.        
  97.     }
Advertisement
Add Comment
Please, Sign In to add comment