retrieving one by one integer from file?


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 :

[code]#include
#include
#include
#include
#include

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 << "
Program was unable to write to file. ";
}
openMode = ios::in;
if (WithDraw(filePath,openMode) != 1)
{
cout << "
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 << "
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
", str, n); */


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

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

char strTemp[100] = "";

fin.getline(strTemp,100, '
');
cout << "
WithDraw amount:" << strTemp;

fin.close();
return 1;
}


[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories