0

I have a function that I am trying to create, which has an attribute that is a two-dimensional array.

However, I am not sure what I am doing.

This is what I have:

class Savings : public Account {
    protected:
        string sTrans[2][2];
        
    public: 
        string transtype;
        void Transfer(string a, string b){          
            if (a == "Debit" || a == "debit"){
                double c = std::stod(b);
                acc_balance = acc_balance - c;
                transtype = "Debit";
            }else if (a == "credit" || a == "Credit"){
                double c = std::stod(b);
                acc_balance = acc_balance + c;
                transtype = "Credit";
            }
        }
};

My goal is to create the array, sTrans[2][2], and then store the data I receive from user inputs.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Andre_Jam
  • 1
  • 1
  • Don't return an array directly, model a struct e.g. `struct TransferResult` let that contain the data needed and return that. The nice thing is that you improve readability : because that's really what you are semantically returning a TransferResult (the WHAT), the underlying array is just an implementation (a HOW) – Pepijn Kramer Jun 30 '22 at 04:01
  • Okay, im not familiar with struct but i will get to reading and try it out. Appreciate it Pepijn. – Andre_Jam Jun 30 '22 at 04:03

0 Answers0