I'm trying to use an array to encode a line from a file and then output the encoded line to a separate file. The program should look to the array to add a number the characters on the ASCII table. So the first element in the array changes the first character in the line from the file and the second one changes the second one and so on through five and then it should start over with the first array element if it is more than the array.
int main()
{
// data
int i; // loop counter (int)
string fileName; // name of file input by the user (string)
string fileLine; // line from the file to encode (string)
ifstream fin; // file input (ifstream)
ofstream fout; // file output (ofstream)
constint SIZE = 5;
int offset[SIZE] = {-5, 8, 12, 6, 1};
int counter = 0;
int index;
char keepGoing;
// prompt user for fileName
cout << "Enter the name of input file you wish to encode [i.e. encode.txt]: ";
getline(cin, fileName);
cout << endl;
// open the file for input
fin.open(fileName.c_str());
if (!fin.good()) throw"I/O error";
// open secret.txt for output
fout.open("secret1.txt");
if (!fout.good()) throw"I/O error";
// convert each character in line by adding and subtracting with the elements in the array
while (fin.good())
{
getline(fin, fileLine);
cout << "Line from file: " << fileLine << endl;
while (true)
{
// cycle through array
int index = counter % SIZE;
cout << offset[index] << endl;
// continue cycling?
cout << "Do you want to continue? [Y/N]: ";
cin >> keepGoing;
cin.ignore(1000, 10);
if (keepGoing == 'n' || keepGoing == 'N') break;
for (i = 0; i < fileLine.length(); i++)
{
fileLine[i] = fileLine[i] + offset[i];
}// for converting
// count loops
counter++;
}// while true
// ouput result to secret1.txt and to console
fout << fileLine << endl;
cout << "Encoded form: " << fileLine << endl << endl;
}// while loop
// clear and close files
fin.clear();
fout.clear();
fin.close();
fout.close();
} // main