bank i need a little tweking

my codes works but i only did the shell of it before i put eveything together. the thing i can't figure out is how to set the account balance to zero and have pop up message saying invalid.

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

// bank account

#include <iostream>
#include <string>

using namespace std;

class Bank
{
      char name[20];
      int AccNumber;
   
      int bal;
      public:
             void OpenBal();
             void deposit();
             void withdraw();
             void display();
};

void Bank::OpenBal()
{
cout<<"Enter Name: ";
cin>>name;
cout<< "Enter Account number:" ;
cin>> AccNumber;
cout << "Enter Opening Balance: ";
cin >> bal;
}

void Bank :: deposit()
{
cout<<"Enter Deposit amount :-";
int deposit=0;
cin>>deposit;
deposit=deposit+bal;
cout<<"\nDeposit Balance = "<<deposit;
bal=deposit;
}

void Bank :: withdraw()
{
int withdraw;
cout<<"\nBalance Amount = "<<bal;
cout<<"\nEnter Withdraw Amount :";
cin>>withdraw;
bal=bal-withdraw;
cout<<"After Withdraw Balance is: "<<bal;
}

void  Bank :: display()
{
cout<<endl<<endl<<endl;
cout<<"DETAILS"<<endl;
cout<<"Name:      "<<name<<endl;
cout<<" Account number:     "<<AccNumber<<endl;

cout<<"Balance: $     "<<bal<<endl;
}

int main()
{

Bank A;
int choice;
    do
    {
           cout<<"\n\nChoice List\n\n";
           cout<<"1)  To assign Initial Value\n";
         cout<<"2)  To Deposit\n";
         cout<<"3)  To Withdraw\n";
         cout<<"4)  To Display All Details\n";
         cout<<"5)  EXIT\n";
         cout<<"Enter your choice : ";
         cin>>choice;
         switch(choice)
         {
         case 1: A.OpenBal();
                     break;
         case 2: A.deposit();
                     break;
           case 3: A.withdraw();
                     break;
         case 4: A.display();
                     break;
            case 5: exit;
         }
   }while(1);
return 0;
}

     
why not use a constructor that sets bal to 0 everytime you create an object ?
i tired to put it where the withdraw is but didn't work so i have make a whole new constructor all together? im kinda confuse how to set it to 0 and place where.
oh i got it thank you pointing me to right way.
Topic archived. No new replies allowed.