Writing Switch or for loop to read character stored in array and update balance ATM Program

Basically I Want to Write either A switch or if loop that iterates through multple array elements and checks if the account number is equal to the customer account number then it should check a character vlue which i want to use 3 cases for deposit ,withdrawl,and interest though interest transactions are stored as a 0.00 value so i do not want to read it in if it is not neccesary.

Then I Will need to declare functions later.
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
[# include <iostream>
# include <fstream>

# define length 4
# define Translength 21
using namespace std;

class savingsAccount
{
      public:
       int accountNumber;
       float balance;
       float intrestRate;
       };savingsAccount account [length];

       class Customer
       {
             public:
              string fName;
              string lName;
              string housenum;
              string streetname;
              string streettype;
              int SavingsAccount;
              };Customer customer [length];


              class Transaction
              {
                    public:
                    int accNumber;
                   float amount;
                    char transType;
                    };Transaction transaction [length];


                    int main ()

                {
                  float balance = 0;
                    float intrestRate = balance*0.05;

ifstream myfile ("customer.dat");

    if (myfile.is_open())
  {
    while ( myfile.good() )
    {  for (int n = 0; n <length; n++)
    {
      myfile >>customer[n].SavingsAccount;cout<<flush;
      myfile >>customer[n].fName;
      myfile >> customer[n].lName;
      myfile >> customer[n].housenum; myfile >> customer[n].streetname;myfile >> customer [n].streettype;
      }

      myfile.close();}
{
ifstream myfile ("trans.dat");

    if (myfile.is_open())
  {
    while ( myfile.good() )
    {  for (int n = 0; n <Translength; n++)
    {
      myfile >> transaction[n].accNumber;
        myfile >> transaction[n].amount;
        myfile >> transaction[n].transType;
    

      }      myfile.close();}
      {


    
    {
         cout << " Customer Report"<<endl<<endl;
            
        for (int n = 0; n<length; n++)
        {
         cout <<" Customer Account Number : "<< customer[n].SavingsAccount<<endl;
         cout <<"Customer Name : "<<customer[n].fName; cout << " " << customer [n].lName<<endl;
         cout << "Customer Address : "<< customer[n].housenum; cout <<" " ;cout<<customer[n].streetname;cout <<" "<<customer[n].streettype<<endl;
         cout << "Account Balance : " <<account[n].balance<<endl;cout<<endl;
        }

        {

cout<<" New Customer Balances"<<endl<<endl;
  for (int n = 0; n<length; n++)
  {
account[n].balance == transaction[n].amount;

        cout <<" Customer Account Number : "<< customer[n].SavingsAccount<<endl;
        cout <<"Customer Name : "<<customer[n].fName; cout << " " << customer [n].lName<<endl;
        cout << "Customer Address : "<< customer[n].housenum; cout <<" " ;cout<<customer[n].streetname;cout <<" "<<customer[n].streettype<<endl;
        cout << "Account Balance : " <<transaction[n].amount<<endl;cout<<endl;
}
{
        system ("pause");

}}}}}}}}/code]

I know the code is quite sloppy and the extra } at the bottom though dev c++ complained about extra } needed


Basically I Have the code reading in from texfile correctly checking the elements though i need to write a function to compare the [code]customer[n].SavingsAccount to the transaction[n].accNumber and then I was thinking of using a switch statement to check the transaction[n].transType; then defining the 3 cases for withdrawl,Intrest and Deposit  


Though i do not know how to write a switch statement that compares the account numbers and reads the array' character and amount to update account [n].balance


Any Help Would Be Greatly Appriciated
Last edited on
Topic archived. No new replies allowed.