Function Not Executing?

Hi, I am working with classes, and I have written a function called withdrawl(char) , and when i call it in main the compiler completely skips it.

My program is just a simple bank.

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
 #include <iostream>
#include <string>

using namespace std;

//Global Bank object


class bank{

private:
	//Class bank variables.
	string name;
	string initials;
	string country;
	char sex;
	char resubmit;
	int age;
	int height;

	//Class Account variables.
	double total_savings;
	double total_cheq;
	double savings_amount;
	double cheq_amount;
	bool verify_cheq;
	bool verify_saving;

public:
	bank();
	void register_user();
	//Class for deposite/withdrawl
	friend class account;
	//Class for displaying user's Card.
	friend class card;
};

bank::bank(){

	total_savings = 500;
	total_cheq= 500;

}

void bank::register_user(){
	system("Color 1F");

	cout<<"Please Fill out the Following Form: "<<endl;

	cout<<"\nName: "; getline(cin,name);
	cout<<"Initials: "; getline(cin,initials);
	cout<<"Country of Birth: "; getline(cin,country);
	cout<<"Sex ( f or m): "; cin>>sex;
	cout<<"Age: "; cin>>age;
	cout<<"Height: "; cin>>height;

	cout<<"\nIs this accurate, would you like to re submit a form? (y or n): "; cin>>resubmit;


	while(resubmit!='n'){

	system("CLS");
	cout<<"Please Fill out the Following Form: "<<endl;
	cin.ignore();
	cout<<"\nName: "; getline(cin,name);
	cout<<"Initials: "; getline(cin,initials);
	cout<<"Country of Birth: "; getline(cin,country);
	cout<<"Sex ( f or m): "; cin>>sex;
	cout<<"Age: "; cin>>age;
	cout<<"Height: "; cin>>height;

	cout<<"\nIs this accurate, would you like to re submit a form? (y or n): "; cin>>resubmit;

	}

	cout<<"Thank you for Choosing this bank, here is a complementary $500 into both your Checking and Savings Account!"<<endl;

}

class account{

public:
	void deposite();
	void withdrawl(char);
	void verify_money(); //Make sure you do not take money out when you have $0.

};

void account::withdrawl(char s_or_c){

	bank m;

	if(s_or_c == 's' && m.verify_saving == true){
		 
		cout<<"Enter amount of money to withdraw: "; cin>>m.savings_amount;

		m.total_savings -= m.savings_amount;

		cout<<"Your Remaining Balance in your Savings Account is: "<<m.total_savings<<endl;
	}
	else if(s_or_c == 'c' && m.verify_cheq == true ){

		cout<<"Enter amount of money to withdraw: "; cin>>m.cheq_amount;

		m.total_cheq -= m.cheq_amount;

		cout<<"Your Remaining Balance in your Checking  Account is: "<<m.total_cheq<<endl;
	}



}

void account::verify_money(){

	bank m;

	if(m.total_cheq <=0)
		m.verify_cheq = false;
	else
		m.verify_cheq = true;

	if(m.total_savings <=0 )
		m.verify_cheq = false;
	else
		m.verify_cheq = true;
}


int main(){

bank m;
account n;

	int option,choice;
	char s_or_c;
	/*cout<<"Welcome to THE Bank!"<<endl;
	m.register_user();

	system("Color 2F");
	system("CLS");*/

	cout<<"For assistance type 1 or any number to leave: "; cin>>option;

	while(option==1){

		cout<<"What would you like to do?"<<endl;
		cout<<"1- Withdraw money"<<endl;
		cout<<"2- Deposite money"<<endl;
		cin>>choice;

		//Withdrwaling money
		if(choice == 1){
			
			cout<<"From Savings (s) or Chequing (c)?"<<endl;
			cin>>s_or_c;
			
			n.verify_money(); // Issue is here, compiler completely skips these two functions.
			n.withdrawl(s_or_c);

			

		}


		//Depositing money
		//if(choice == 2){


		//}

		system("CLS");
	}

	return 0;
}
closed account (E0M1hbRD)
New guy here. Hello to all. It seems to me that those member functions ARE actually being called (try setting up a cout msg in them) but then the program immediately goes back to the while loop they are nested in and the menu pops up again. Maybe nest the funcs in question in an if statement? e.g...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
while(option==1){

		cout<<"What would you like to do?"<<endl;
		cout<<"1- Withdraw money"<<endl;
		cout<<"2- Deposite money"<<endl;
		cin>>choice;

		//Withdrawling money
		if(choice == 1){
			
			cout<<"From Savings (s) or Chequing (c)?"<<endl;
			cin>>s_or_c;

		}

		if(s_or_c == 's'){
		n.verify_money(); // Issue is here, compiler completely skips these two functions.
		n.withdrawl(s_or_c);
		}

		//else{blah blah blah}

		//Depositing money 


...Someone might have a more elegant solution; I'm new here. I didn't read the whole code, just the problem area. Great forum!
Last edited on
Topic archived. No new replies allowed.