having a little problem

hello everyone, i have this program that is like an ATM. it ask the user to deposit or see the balancce it works fine but i do not how to show the balance that i have in deposit1() when the user select the option chect the balance that is in Menu3() how can i show the result that i have in deposit1() in that menu3()please help
this is my program
#include <iostream>
#include <iomanip>
//#include <fstream>
//#include <string>

using namespace std;

void Menu()// prinsipal manu with the three options
{
cout << "**************************************************" << endl;
cout << "****** Welcome to MyBank ATM ******" <<endl;
cout << "****** Your Friend in the Markets ******" <<endl;
cout << "**************************************************" << endl << endl;
cout << " How can I help up you today?"<<endl<<endl;
cout << " 1) Deposit Money " << endl;
cout << " 2) Check the balance " << endl;
cout << " 3) Noting. Exitt " << endl;
cout << " ------------------------------------- " << endl;
}
int deposit1()
{
int sum=0,x,C,z=0;

for (int i=0; i<=sum; i++ )
{
cout << "Please enter the amount you want to deposit" << endl;
cin>>C;
z=C+z;
cout <<"1) deposit more "<<endl;
cout <<"2) complete deposit "<<endl;
cin>>x;
if (x==1)
{
system ("CLS");
sum=sum+1;
}
else
{
cout <<"total deposit"<<z<<endl;
system("CLS");
Menu();
}


}
// system ("CLS");
return 0;
}
int deposit2()
{
int sum=0,F,C,x,z=0;

for (int i=0; i<=sum; i++ )
{
cout <<"intro deposit "<<endl;
cin>>C;
z=C+z;
cout <<"1) deposit more "<<endl;
cout <<"2) complete deposit "<<endl;
cin>>x;
if (x==1)
{
system ("CLS");
sum=sum+1;
}
else if (x==2)
{
Menu();
cin>>x;
}
else
cout<<"invalid entry "<<endl;
Menu();
cin>>x;
}
// system ("pause");
return 0;
}
void Menu2() // manu2 with the two remaining options
{
int y,a,b;
cout << " Please make your selection " << endl<<endl;
cout << " 1) Depositing into Checking " << endl;
cout << " 2) Depositing into Savings " << endl;
cout << " 3) Back to Main Menu " << endl;
cout << " --------------------------------" << endl;
cin >> y;
if(y==1)
{
system("CLS");
cout << " Depositing into Checking Started" << endl;
deposit1();
}
else if(y==2)
{
system("CLS");
cout << " Depositing into Savings Started" << endl;
cout << "Please enter the amount you want to deposit" << endl;
deposit2();
}
else if(y==3)
{
system("CLS");
Menu();
}
else
{
cout << " Invalid Entry " << endl << endl;
cout << " Please Select Option 1, 2 or 3" << endl;
Menu2();
cin >> y;
system("CLS");
}

}
void Menu3() // menu3 with the two remaining options
{

cout << "Your Checking Balance = " << endl;
cout << "Your Saving Balance = " << endl << endl;
cout << "Please make your selection " << endl;
cout << "1) Deposit More Money " << endl;
cout << "3) Noting. Exit " << endl;
cout << "--------------------------" << endl;
}

int main()
{
int y,x;
Menu();
cin >> x;
system("CLS");

while (x != 3)// exit the program with the option 3 that is exit
{
if (x == 1)// option 1
{
system("CLS");
cout << "**************************************************" << endl;
cout << "***** Thank you for Depositing Funds Today ****" << endl;
cout << "**************************************************" << endl << endl;
Menu2();
cin >> x;
//system("CLS");
}
else if (x == 2)//option 2
{
system ("CLS");
cout << "**************************************************" << endl << endl;
Menu3();
cin >> x;
system("CLS");
}
else // if you enter any other number that is not in the options
{
cout << " Invalid Entry " << endl << endl;
cout << " Please Select Option 1, 2 or 3" << endl;
Menu();
cin >> x;
system("CLS");
}
}
cout << " Exiting from the Program " << endl;

//system("pause");
return 0;
}
The not recommended way but easiest way would be to declare two global variables initialised to zero, checkingBalance and savingsBalance and use them in all functions that need them.

The recommended way is to declare them in main() and pass them as references to all the functions but you will have to study up on function parameters and arguments.


"****** Your Friend in the Markets ******"
Sure!
Last edited on
Topic archived. No new replies allowed.