hi ...

i am making a program which can handle bank acount system.

In which User can MakeDeposite,WithDraw money and CheckRemainingBalance.

when user MakeDeposite then a certain amount should be saved and as how much times user

MakeDeposit, it should be added in balance amount and as how much times user

WithDraw, it should also be stored and maintain

Remaining Balance (thorugh subtracting that amount)

i hav made it. but one error is still not handled.
when i do Makedeposite more than once, it replaces the amount of file but it should be


Code:
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

int MakeDeposit(int amount,char filePath[], int openMode);
int WithDraw(int amount,char filePath[], int openMode);
int CheckRemaingBalace(char filePath[], int openMode);
int tempStore=0;
int main()
{
	int depositedAmount=0,withDrawAmount=0,tempForAmount=0;
	clrscr ();

	char filePath[] = "f:\\anyFile.txt",temp;
      //	int openMode  = ios::out | ios::app;
      while(1)
      {
	clrscr();
	cout<<"Press 1 to Deposite amount:";
	cout<<"\nPress 2 to withdraw:";
	cout<<"\nPress 3 to Check Balance:";
	cout<<"\nPress e or q to exit the program:";
	cout<<"\nPress any key to clear:";
	cout<<"\nWrite your Optione:";
	temp = getche();
	switch(temp)
	{
		case '1':
		 cout<<"\nEnter Amount to deposit in your account:";
		 cin>>depositedAmount;
		 tempForAmount +=depositedAmount;
		 int openMode  = ios::out;
		 if (MakeDeposit(tempForAmount,filePath,openMode) != 1)
		 {
			cout << "\n Program was unable to write to file. ";
		 }
		break;
		case '2':
		cout<<"\nEnter Amount to WithDraw:\n";
		 cin>>withDrawAmount;
		 openMode  = ios::out;
		 if ( WithDraw(withDrawAmount,filePath,openMode) != 1)
		 {
			cout << "\n Program was unable to write to file. ";
		 }
		break;
		case '3':
		openMode = ios::in;
		if (CheckRemaingBalace(filePath,openMode) != 1)
		{
			cout << "\n Program was unable to read from file. ";
		}
		break;
		case 'e':
		case 'q':
		exit(0);
		break;
		default:
		cout<<"\n Option invalid!";
		break;
	}

	 getch();
      }

	return 0;
}
int MakeDeposit(int amount,char filePath[], int openMode)
{
       ofstream fout(filePath, openMode);

	if (!fout)
	{
		cout << "\n Unable to open file for writing. Now exiting...";
		return -1;
	}
	int openMode2 = ios::in;
	ifstream fin(filePath, openMode2);

	if (!fin)
	{
		cout << "\n Unable to open file for reading. Now exiting...";
		return -1;
	}

	char strTemp[100] = "";
	fin.getline(strTemp,100, '\n');

	tempStore = atoi(strTemp);
	if(strTemp=="")
	{
	   itoa(amount, strTemp, 10);
	   cout<<"\n\nSuccessfully stored !";
	   fout.write(strTemp, strlen(strTemp));
	}
	else if(strTemp!="")
	{
		tempStore+=amount;
		itoa(tempStore, strTemp, 10);
		cout<<"\n\nSuccessfully stored !";
		fout.write(strTemp, strlen(strTemp));
	}

	fin.close();
	fout.close();
	return 1;
}
int WithDraw(int amount,char filePath[], int openMode)
{
	ifstream fin(filePath, openMode);

	if (!fin)
	{
		cout << "\n Unable to open file for reading. Now exiting...";
		return -1;
	}

	char strTemp[100] = "";
	fin.getline(strTemp,100, '\n');
	int n=0;
	n = atoi(strTemp);
	n = n - amount;
	cout<<"\nSuccessfully WithDraw amount:"<<amount;
	int openMode2  = ios::out;
	if (MakeDeposit(n,filePath,openMode2) != 1)
	 {
		cout << "\n Program was unable to write to file. ";
	 }

	fin.close();
	return 1;
}
int CheckRemaingBalace(char filePath[], int openMode)
{
	ifstream fin(filePath, openMode);

	if (!fin)
	{
		cout << "\n Unable to open file for reading. Now exiting...";
		return -1;
	}

	char strTemp[100] = "";
  
	fin.getline(strTemp,100, '\n');
	cout << "\n CheckRemaingBalace amount:" << strTemp;

	fin.close();
	return 1;
}