ATM machine

Here's one for some of you! I thought I'd try to make a novice ATM machine, the program takes the pin you wish to use and stores that, when you want to change the pin it checks if the new pin you've entered is the same as the old pin and it then overwrites the memory address of the original pin value with the new pin value... But I think the problem is the new pin not overwriting the original pin.
Thanks for the help in advance :)

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

void CreatePin();
void StorePin();
void ChangePin();
void OverWritePin(int *x);
void AlterPin(int pin);

int pin;
int newPin;

int main(){
	CreatePin();
	//test cout << "Current pin is... " << pin << endl;
	ChangePin();
	//test cout << "Changed pin is now... " << newPin << endl;
	//test cout << "Old pin test... " << pin << endl;
	//test cout << "New pin test... " << newPin << endl;
}

void CreatePin(){
	cout << "Enter 4 digits and press enter to create your new pin!" << endl;
	StorePin();
}
void StorePin(){
	cin >> pin;
	int *pinPointer = &pin;
}
void ChangePin(){
	cout << "Enter your current pin to pass the security stage." << endl;
	cin >> newPin;
	AlterPin(newPin);
};
void OverWritePin(int *x){
	*x = newPin;
};
void AlterPin(int pin){
	if(pin==newPin){
		OverWritePin(&pin);
	}
};
Last edited on
*edit*
Last edited on
Hi, this:

1
2
3
4
5
void AlterPin(int pin){
	if(pin==newPin){
		OverWritePin(&pin);
	}
};


should be changed to this:
1
2
3
4
5
void AlterPin(int &pin){
	if(pin!=newPin){
		OverWritePin(pin);
	}
};
The previous version of the function checked if the new pin equaled the pin, then it changed the pin to the new pin. Basically, it changed the value to it's previous value. This way, if the pin doesn't equal the new pin, then the pin is changed.

(Confusing, I know.)

EDIT: By the way, functions don't require semi-colons to be appended on the end of them.
Last edited on
Thanks for the response but that code doesn't seem to work, have you tried it??
This pointer is destroyed at the end of this function

Also you never call it again anyway so the the whole function is redundant.

1
2
3
4
void StorePin(){
	cin >> pin;
	int *pinPointer = &pin;
}


I dont think you quite understand how to use pointers and references yet.
So maybe look over them again

Also why do you have semicolons at the end of half your functions ?

And is there really a need for all the functions ?

I honestly dont even know what you are trying to do in half of them.

There's not really any need for pointers at all, unless of course youre just using them to learn, as you have used global variables so they are visible to all functions

Anyway

I made this really quick to give you an idea of how i would do it

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

void CreatePin();
void StorePin();
void ChangePin();
void OverWritePin();
void AlterPin();

int pin;
int newPin;

int main()
{
	CreatePin();

	ChangePin();
}

void CreatePin()
{
    cout << "Input new pin: " ;
    cin >> pin;
}

void ChangePin()
{
    cout << "Input old pin to pass security stage:";
    int x = 0;
    cin >> x;
    if(x==pin)
        OverWritePin();
    else
        cout << "Pin incorrect";
}
void OverWritePin()
{

}
void AlterPin()
{

}


Obviously ive left some for you to do :)
Hope it helps.
Topic archived. No new replies allowed.