c++ 여기서 막히네요...

tormsgkfrhdi의 이미지

만약에 은행잔고가 651.45가 남아야하는데 에러로 인해 451.56이 남았을경우에 바로잡아주는 프로그램을 어떻게 만들어야할까요?????참고로 cpp입니다...

#include
#include
#include
#include

using namespace std;

int main()
{
ifstream inFile, inSortFile;
ofstream outFile;
ifstream checkFile;
string inFileName, outFileName, ID, balance;

do
{
cout << "What is the name of the file you would like to read from? ";
cin >> inFileName;
inFile.open(inFileName.c_str());
if(inFile.fail()) cout << "The file called " << inFileName << " does not exist." << endl;
}while(inFile.fail());

cout << "The file was opened." << endl;
cout << "Where would you like to output the data: ";
cin >> outFileName;

checkFile.open(outFileName.c_str());

if(!checkFile.fail())
{ //opening outer if
cout << "A file with the name " << outFileName << " already exists." << endl
<< "Do you wish to overwrite the file? Enter n or N if no, anything else if yes: ";

char answer;
cin >> answer;

if(answer=='n'||answer=='N')
{ //opening inner if
cout << outFileName << " will not be overwritten.\n";
system("PAUSE");
exit(1);
}
}

checkFile.close();
outFile.open(outFileName.c_str());
cout << "The data was successfully output to " << outFileName << "." <

int count = 0;
while(inFile.good())
{
inFile >> ID >> balance;
outFile << ID << " " << balance << endl;
}

return 0;
}

kalevala의 이미지

숙제가 아니셨다면 실례였겠습니다만, 그 이전에 문제의 정의가 애매하군요.

굳이 추측해보자면, 은행 계좌에 접근하였던 일련의 log들과 현재 잔고를 비교하였을 때

발생하는 에러가 질문에서 말씀하신 '에러'를 일컫는게 맞는지요 ?

tormsgkfrhdi의 이미지

만약에 infile에서 155.65로 되어있다면
outfile 에는 655.51로 나와야한다는거죠^^;

tormsgkfrhdi의 이미지

#include
#include
#include
#include //to use exit(1)

using namespace std;

int main()
{
ifstream inFile, inSortFile;
ofstream outFile;
ifstream checkFile;
string inFileName, outFileName, ID, balance;

cout << "Enter the filename to be read from:";
cin >> inFileName;

inFile.open(inFileName.c_str());

if(inFile.fail())
{
cout << "The file called " << inFileName << " does not exist.\n"
<<"Check that the file exists.\n";
}
else
cout << "The file was opened." << endl;

cout << "Enter a filename to be written to: ";
cin >> outFileName;

checkFile.open(outFileName.c_str());

if(!checkFile.fail())
{
cout << "A file with the name " << outFileName << " already exists." << endl
<< "Do you wish to overwrite the file? Enter n if no, anything else if yes: ";

char overwrite;
cin >> overwrite;

if(overwrite=='n')
{ //opening inner if
cout << outFileName << " will not be overwritten.\n";
system("PAUSE");
exit(1);
}
else
cout << "The file " << outFileName << " will be overwritten.\n";
}

checkFile.close();
outFile.open(outFileName.c_str());
cout << "The data was successfully output to " << outFileName << "." <

inFile.seekg(0L,ios::end);
long int lastChar=inFile.tellg();
long int offset;
for(offset=1; offset<=lastChar;offset++)
{
inFile.seekg(-offset,ios::end);
char c=inFile.get();
outFile< }
inFile.close();
outFile.close();
system("pause");
return 0;

int count = 0;
while(inFile.good())
{ //opening while
inFile >> ID >> balance;
outFile << ID << " " << balance << endl;
} //closing while

system("pause");
return 0;
}