Function

Hi. I'm building a code for ATM machine. It doesn't have to be perfect, but my function is appearing as an error for makeDeposit and MakeWithdrawl and printBalance. The ................ is already filled in for me.

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
#include <iostream>
#include <fstream>
using namespace std;



bool pinIsValid(int);
double getBalance(string);
int makeSelection();
void makeDeposit(double,double);
void makeWithdrawl(double,double);
void printBalance (double);

int main()
{
	cout<<"Enter pin";
	int pin;
	double curBal, amt;
	cin>>pin;
	if(pinIsValid(pin)){
	curBal=getBalance("C:\\Documents and Settings\\.........\\Desktop\\ATM.txt");

	switch(makeSelection())
		{
		case 1:
			cout << "Enter a deposit amount: ";
			cin >> amt;
			makeDeposit(curBal,amt);
			break;
		case 2:
			cout << "Enter a Withdrawl amount: ";
			cin >> amt;
			makeWithdrawl(curBal,amt);
			break;
		case 3:
			cout << printBalance(curBal);
			break;
		}
	}
	else 
	{
		cout << "Invalid Pin!" << endl;
	}
	system ("PAUSE");
	return 1;
}
bool pinIsValid(int pin)
	{
	return 1234;
	}
double getBalance(string path)
	{
		
		ifstream infile;
		double bal = 1000;
		infile.open("C:\\Documents and Settings\\......\\Desktop\\ATM.txt");
		infile >> bal;
		infile.close();
		return getBalance("C:\\Documents and Settings\\......\\Desktop\\ATM.txt");
	}
int makeSelection()
	{
		cout << "Press 1 - Deposit" << endl;
		cout << "Press 2 - Withdrawl" << endl;
		cout << "Press 3 - Current Balance" << endl;
		return makeSelection();
	}
void makeDeposit(double &bal, double DepAmt)
	{
		bal+=DepAmt;
		cout << "Your current Balance is now: " << bal;
	}
void makeWithdrawl(double &bal, double WithAmt)
	{
		bal-=WithAmt;
		cout << "Your current Balanace is now: " << bal;
	}
void printBalance (double &bal)
	{
		cout << bal; 
	}
Last edited on
printBalance doesn't return anything, hence you can't cout it. Just call the function since you already have a cout inside of it.

Whatever you're getting that's undefined, it's because in your prototype you didn't include & at the end of double. (3 functions, all the first parameter)

Edit: Why don't you just cout<< curBal; instead of passing it to a function that does exactly that?

makeSelection doesn't do any operations, it's just a function that cout a bunch of stuff. There's nothing to return, you can just make it void and remove the return. In fact the way you're returning makeSelection puts it into a recursive loop and it'll end up going on forever.

getBalance also goes into a recursive loop and doesn't look like there is any way to stop it. That will go on forever as well. Try return bal instead (no idea if this is your intention, but I suppose considering your return type).

What if the pin passed to pinIsValid is false? That function is only capable of returning true.
Last edited on
OMG Thank you for your help cant believe i made a simple mistake
Last edited on
Topic archived. No new replies allowed.