0

Yes, I finally figured it out, just had to add another condition inside if(i==1). I just added that the value of the array balance at the cell three cells away from the length of the string must be '.' . Thanks a lot WaltP, I really appreciate it.

Can you please post your full code?

0

Can you please post your full code?

#include<fstream>
#include<iostream>
#include<string>
#include<cstdlib>

using namespace std;

int main()
{
    ifstream inFile, inSortFile;
    ofstream outFile;     
    ifstream checkFile;
    string inFileName, outFileName, ID, bal;
    
        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 " << inFileName << " does not exist." << endl;
                system("pause");
                return 0;
            }
    
    cout << "The file was opened." << endl;
    cout << "Please enter the output file name: ";
    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 answer;
            cin >> answer;
            
            if(answer=='n')
            {
                cout << outFileName << " will not be overwritten." <<endl;
                system("PAUSE");
                exit(1); 
            }
        }
        
        checkFile.close(); 
        outFile.open(outFileName.c_str());
        
    while(inFile.good())
    {
         inFile >> ID >> bal;
         outFile << ID << " ";
         int len = bal.length();
         for(int i = len-1; i>=0; i--)
         {
 
            if (i==1&&bal[len-3]=='.')
            {
                outFile << '.';
            }
            if (bal[i]!='.')
            {
                outFile << bal[i];
            }
         }              
         outFile << endl;
     }

    cout << "The data was successfully output to " << outFileName << "." <<endl;
system("pause");
return 0;
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.