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 many times user
WithDraw, it should also be stored and maintain
Remaining Balance (thorugh subtracting that amount)
i have written some code, please see it and correct it :
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
int WithDraw(char filePath[], int openMode);
int MakeDeposit(int amount,char filePath[], int openMode);
int main()
{
int amount=0;
clrscr ();
char filePath[] = "anyFile.txt";
int openMode = ios::out | ios::app;
cout<<"Enter Amount to deposit in your account:";
cin>>amount;
if (MakeDeposit(amount,filePath,openMode) != 1)
{
cout << "\n Program was unable to write to file. ";
}
openMode = ios::in;
if (WithDraw(filePath,openMode) != 1)
{
cout << "\n Program was unable to read from file. ";
}
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;
}
char str[25];
itoa(amount, str, 10);
fout.write(str, strlen(str));
/* int n;
char *str = "12345.67";
n = atoi(str);
printf("string = %s integer = %d\n", str, n); */
fout.close();
return 1;
}
int WithDraw(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 WithDraw amount:" << strTemp;
fin.close();
return 1;
}