C and Cpp

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDesktop ProgrammingC and Cpp

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old October 30th, 2009, 03:27 PM
maifs maifs is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 1 maifs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 58 sec
Reputation Power: 0
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 <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;
}







Reply With Quote
Reply

Viewing: Tutorialized ForumsDesktop ProgrammingC and Cpp > Retrieving one by one integer from file?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap