YAY!!!!

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?

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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.