C++ Problem - Simple Bank transaction system

Hi - I can't seem to make this program work, and I believe that the main issue I'm having is in reading the data from my input file. I would deeply appreciate any advice.

Here is a link to the given problem:

http://www.sci.brooklyn.cuny.edu/~ziegler/CISC1110/HW/HW7_BankAccounts.pdf

Basically:
you have been hired as a programmer by a major bank. Your first project is a
small banking transaction system. Each account consists of a number and a balance.
The user of the program (the teller) can create a new account, as well as perform deposits,
withdrawals, and balance inquiries.


Here is the program I have written so far - I've focused on reading the balance from 2d parralele arrays in a txt file and displaying it. For some reason I'm struggling in setting the integer that would correspond to withdrawal to.

// you have been hired as a programmer by a major bank. Your first project is a
// small banking transaction system. Each account consists of a number and a balance.
// The user of the program (the teller) can create a new account, as well as perform deposits,
// withdrawals, and balance inquiries.

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;


// declare and open the input file
ifstream infile("c:\\?\\myinput7.txt"); //comment-out for debugging
//ifstream infile("con"); //un-comment for debugging


// declare and open the output file
ofstream outfile("c:\\?\\myoutput7.txt"); //comment-out for debugging
//ofstream outfile("con"); //un-comment for debugging

void menu()
{
cout <<"Enter W for Withdrawal " << endl;
cout <<"Enter D for Deposit " << endl;
cout <<"Enter N for New Account " << endl;
cout <<"Enter B for Balance " << endl;
cout <<"Enter Q to Quit " << endl;
cout <<"Enter X to Delete Account " << endl;
}
int main ()
{
int acctnum_array[0],max_accts[0];
double balance_array[0];
bool not_done = true;
char choice;
do
{
menu();
cin>>choice;
switch (choice)
{
case 'B':
case 'b':
{
for(int i = 1; i < 50; i++)
{
infile.open ("myinput7.txt");
while (!infile);
cout<<"there was an error opening the file." <<endl;
int read_accts(int acctnum_array[], double balance_array[], int max_accts);
cout << "enter account ID : " << endl;
cout << acctnum_array[0] << endl;
cout << balance_array[0] << endl;
}
}
break;
case 'W':
case 'w':
{
for(int i = 1; i < 50; i++)
{
int w;
infile.open ("myinput7.txt");
while (!infile);
cout << "enter account ID and amount to withdraw: " << endl;
cout << acctnum_array[0] << w << endl;
cout >> "Enter amount to withdraw" << endl;
cin >> w ;
cout << endl;
cout << "remaining balance for" << acctnum_array << is << (balance_array[0]-w) << endl;
}
}
break;
case 'Q':
case 'q' :
not_done=false;

break;
default:
cout<< choice<< " is not a valid selection. Try again.";
break;
}
}
while (not_done);
return 0;
}


again, I would deeply appreciate any help that you could provid.

Thanking you all in advance.

I'd advise you to use the code tags to make the code more readable. Your withdraw code section has some errors. It's actually pretty straightforward, you just need to read the arrays from the file one time, once you get them, just work with the arrays.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
void withdrawal(int acctnum_array[], double balance_array[], int num_accts)
{ 
   int unsigned acct_pos=0; //variable to store account position
   bool found=false;           //variable checking if the account exists
   
   int account_number;
   std::cout<<"Please input your account number\n"; 
   std::cin>>account_number; //prompts the user to insert account number

   for(; acct_pos<num_accts;++acct_pos)
    if(acctnum_array[acct_pos]==account_number) // searches the account
       {
          found=true;
          break;
       }

   if(!found) //if there is no account
       {  
           std::cout<<"ERROR! Account not found!"; // tells user
           return; //exits function
       }

   int unsigned amount;
   std::cout<<"Introduce the amount you want to withdraw\n";
   std::cin>>amount; //prompts the user to insert amount to withdraw
   
   if(balance_array[acct_pos]>=amount) //checks if the user has sufficient funds
      balance_array[acct_pos]-=amount; // if he does, then withdraw the amount
   else std::cout<<"ERROR! Insufficient fund!\n"; //else display error message

}
Last edited on
Topic archived. No new replies allowed.