I am using VC++. I want to display to the user all data that is stored in an input file and an output file. My input file contains the following so far but will continue to grow as the user uses it:
100.00
123.45
234.56
212.45
Here is what my output file has stored but it also will grow as the user uses the program:
$100 February 10, 2006 2:35:34PM
$23.45 February 10, 2006 2:55:54PM
and so on....
my code so far:
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include <ctime>
#include<stdio.h>
#include<conio.h>
#include<iterator>
#include<vector>
using namespace std;
int main()
{
fstream inputOne;
inputOne.open("inputData.txt");
fstream depositInput;
depositInput.open("inputData.txt");
fstream inputTwo;
inputTwo.open("inputData.txt");
ifstream history( "inputData.txt" );
istream_iterator<double> begin( history );
istream_iterator<double> end;
vector<double> input( begin, end );
ofstream outputTwo;
outputTwo.open("outData2.txt",ios::app);
cout<<fixed<<setprecision(2);
float amount,total,totalTwo;
string copyright="©";
int selection;
struct tm *ptr;
time_t tm;
char str[60];
char str1[60];
tm = time(NULL);
ptr = localtime(&tm);
strftime(str ,100 , "Today is %B %d, %Y. The current time is: %I:%M:%S %p.\n",ptr);
strftime(str1,100,"%B %d, %Y - %I:%M:%S %p",ptr);
cout<<str<<endl;
cout<<"Welcome to the Automated Teller Machine Program."<<endl;
cout<<'\n';
cout<<"What would you like to do today?"<<endl;
cout<<"(1)Withdraw"<<endl;
cout<<"(2)Deposit"<<endl;
cout<<"(3)View Withdrawal & Deposit History"<<endl;
cout<<"(4)Exit"<<endl;
cout<<"(5)About"<<endl;
cout<<"Please choose an option by pressing (1), (2), (3), (4), or (5): ";
cin>>selection;
switch (selection)
{
case 1:
cout<<"How much would you like to withdraw? $";
cin>>amount;
while(amount<=0)
{
cout<<"Please enter a positive non-zero withdrawal amount: $";
cin>>amount;
}
while(inputOne.eof() == 0)
{
inputOne>>total;
}
inputOne.close();
totalTwo=total-amount;
inputTwo.seekp( 0, ios::end );
inputTwo<<'\n'<<totalTwo;
cout<<"Here is your new balance: $"<<totalTwo<<endl;
outputTwo<<"-$"<<amount<<" - "<<str1<<'\n';
inputTwo.close();
outputTwo.close();
break;
case 2:
cout<<"How much would you like to deposit? $";
cin>>amount;
while(inputOne.eof() == 0)
{
inputOne>>total;
}
inputOne.close();
totalTwo=total+amount;
depositInput.seekp( 0,ios::end );
depositInput<<'\n'<<totalTwo;
cout<<"Here is your new balance: $"<<totalTwo<<endl;
outputTwo<<"+$"<<amount<<" - "<<str1<<'\n';
depositInput.close();
outputTwo.close();
break;
case 3:
cout<<"Here is your withdrawal and deposit history: "<<endl;
cout<<setfill('*')<<outputTwo<<setw(30)<<history<<endl;
outputTwo.close();
break;
case 4:
cout<<"Good Bye."<<endl;
break;
case 5:
cout<<"The Automated Teller Machine Program"<<endl;
cout<<"Copyright "<<copyright<<"2005"<<endl;
cout<<"ChackoItty Corporation"<<endl;
break;
default:
cout<<"Incorrect selection. Good Bye."<<endl;
break;
}
cout<<"Exiting the program.... please press any key"<<endl;
getch();
return 0;
}