0

I'm trying to write a program that simulates an ATM. The user can log in with a pin and account number, check their account balance, and make a withdrawal. I'm having trouble initializing the array that contains the account information, here's what I have so far:

#include <iostream>
#include <string>
using namespace std;

class Account
{
  private: int accountNum;
           string accountPin;
           double balance;
           void setPin();
           void setAccountNum();
  
  public: Account ()//default constructor
            {
              accountNum = -1;
              accountPin = -1;
              balance = 0.0;
             };
          
          Account (int accountNum, string accountPin, double balance)
          //overloaded construtor
           {
            accountNum = accountNum;
            accountPin = accountPin;
            balance = balance;
            };
          
          void setAccountBalance(double bal);//acc balance setter
          
          int getAccountNum() //acc balance getter
            { 
            return balance;
            }
          
          bool confirmPin(string)//confirm pin# func
            {

            }
          void updateBalance(double)
    
  
};

int main () 
{
  int option;
  //accounts array
  Account account[]= (123, "abc123", 100.00), (456, "def456", 50.00),(789,"ghi789", 500.63);

  
  //login code, unfinished
  cout << "LOGIN\nEnter Account#: "<< endl;
  cin >> accNum;
  cout << "Enter pin#: "<<endl;;
  getline(accPin);


//menu do while loop, unfinshed
do {

  cout << "1. Check balance\n2.Make a deposit\n3.Logout\n";
  cin >> option; 

    switch (option)
    //check balance case
    case 1: 
    // make a deposit case
    case 2:

}
while (option !=3);
return 0;
}

Line 48 is where the array needs to be initialized, it contains the account number, the pin code, and the account balance (in that order). Can anyone point out the mistake I'm making? Thanks for the help in advance.

1 Answer 1

2

You need curly braces around the entire initializer list, and also around the initializer for each element.

Account account[]= {
    {123, "abc123", 100.00}, 
    {456, "def456", 50.00},
    {789,"ghi789", 500.63}
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.