Okay the text on my input file is
Wxmv_bpm_xwl_jig_lwwza,_PIT._Q'u_awzzg,_Lidm._Q'u_inziql_Q_kiv'b_lw_bpib.
Here's My code but for some reason I can't get my program to convert the message to my output.txt file. Can someone please help thanks
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
string str;
int shift;
char inChar;
char outChar;
char c;
ifstream inputFile("INPUT.txt");// Opening INPUT.txt file
ofstream outputFile("OUTPUT.txt");// Opening OUTPUT.txt file
if(!inputFile){// Checking for errors or existence of INPUT.txt file
cout << "Error...file INPUT.txt doesnt exist.\n";
exit(1);
}
if(!outputFile){// Checking for errors or existence of OUTPUT.txt file
cout << "Error...file OUTPUT.txt doesnt exist.\n";
exit(1);
}
cout << "Enter an amount to shift by: "; // Prompting users for shift amount
cin >> shift;
if(shift<-9|| shift>9){ // Liminting range of shift numbers between -9 and 9
cout<< "Shift must be a number between -9 and 9.\n";
}else
{if(!inputFile){ // Checking for errors in INPUT.txt file
cout << "Error...file INPUT.txt doesnt exist.\n";
exit(1);
}
if(!outputFile){ // Checking for errors in OUTPUT.txt file
cout << "Error...file OUTPUT.txt doesnt exist.\n";
exit(1);
}
while(getline(inputFile,str)){ // Running If then statements to make the correct code show up
for(int i=0; i<str.length();i++){
inChar =str[i];
if( inChar >= '0' && inChar <= '9' ) {
outChar = inChar - '0';
outChar += 10 + shift;
outChar %= 10;
outChar += '0';
cout<< outChar;
}
if( inChar >= 'a' && inChar <= 'z' ) {
outChar = inChar - 'a';
outChar += 26 + shift;
outChar %= 26;
outChar += 'a';
cout << outChar;
}
if( inChar >= 'A' && inChar <= 'Z' ) {
outChar = inChar - 'A';
outChar += 26 + shift;
outChar %= 26;
outChar += 'A';
cout << outChar;
}
}
inputFile >> str; //Saving to the output file.
outputFile << outChar;
cout << outChar << endl;
}
inputFile.close();// Closing INPUT.txt file
outputFile.close();// Closing OUTPUT.txt file
}
}