C++ ATM program im in desperate moment now.

Hello guys!!i am so desperate now .i cant seem to get the past value for the balance when i prompt the user to make a new transaction.the deposit balance wont saved .:( .and i want to use ofstream for Pin account and password.any help? this is my code so far.i need answers asap please:(.this project due 2days from now...

#include <iostream>
#include <string>
#include <fstream>

using namespace std;
void menu();

void userinput();
void displaybalance(int x);
int depositbalance(int a, int b);
int withdrawSum(int x, int y);
void accountinput();
int balanceholder(float x);


int main()
{

accountinput();
userinput();

}
void accountinput(){
ofstream myfile;
string pinnumber;
string password;
myfile.open("example.txt");

cout << "Enter your Pin Number :" << endl;
getline(cin, pinnumber);
cout << "Enter your Password:" << endl;
getline(cin, password);
system("pause");

}


void userinput()
{


int balance;
int deposit, withdraw, choice;
int answer;
balance = 0;


cout << "Welcome to J & J ATM Machine\n";
cout << "[1]Display Balance \n";
cout << "[2]Deposit Money:\n";
cout << "[3]Withdraw Money\n";
cout << "[4]Exit;\n";
cout << "Enter your Choice:";
cin >> choice;

while (choice != 4)
{
switch (choice)
{
case 1:
displaybalance(balance);
system("pause");
break;
case 2:

cout << "Your Current Balance is " << balance << endl;

cout << "How much Money you want to deposit:" << endl;
cin >> deposit;
balance = depositbalance(balance, deposit);


cout << "Your newbalance is :" << endl;
cout << balance;
cout << endl;
cout << " PRESS 4 TO MAKE A NEW TRANSACTION AND PRESS 5 TO EXIT?" << endl;
cin >> answer;
if (answer == 4 || answer == 4)
return userinput();
else if (answer == 5 || answer == 5)
return;
else
cout << "Please Enter a Valid choice" << endl;


break;

case 3:
cout << "Your Current Balance is " << balance << endl;
cout << "How much Money do you want to withdraw:" << endl;
cin >> withdraw;
if (withdraw > balance)
cout << "Sorry you don't have enough money to withdraw" << endl;
else if (withdraw <= 0)
cout << "sorry amount can not be zero or negative" << endl;
else
balance = withdrawSum(balance, withdraw);
cout << "You Withdraw :" << withdraw << endl;
cout << "Your newbalance is :" << endl;
cout << balance<<endl;

cout << " PRESS 4 TO MAKE A NEW TRANSACTION AND PRESS 5 TO EXIT?" << endl;
cin >> answer;
if (answer == 4 || answer == 4)
return userinput();
else if (answer == 5 || answer == 5)
return;
else
cout << "Please Enter a Valid choice" << endl;
return;
}


cout << "Enter Your Choice:" << endl;
cin >> choice;


}


}

void displaybalance(int x)
{
cout << "Your Balance is :" <<x<< endl;
}

int depositbalance(int a, int b)
{

int newbalance = a + b;
return newbalance;


}

int withdrawSum(int x, int y)
{
int newbalance = x - y;
return newbalance;
}
float balanceholer(int x)
{


}
it's this:
 
return userinput();


this is messed up because firstly userinput returns void() so why do it like this?
More importantly, everytime you call userinput(), it resets your balance back to zero.

also this is a bit mental too:
 
if (answer == 4 || answer == 4)

Topic archived. No new replies allowed.