Feb 9, 2017 at 3:25pm UTC
I making a program that suppose to read a file that was given by user and translates it to rot13. I tested the program it reads the file but it does not convert it to rot13. How can I fix the while loop.
1 2 3 4 5 6 7 8 9 10 11 12 13
char rot13;
while (inFile){
inFile.get(rot13);
if (rot13>='A' &&rot13<='M' )
rot13+=13;
if (rot13>='a' &&rot13<='m' )
rot13+=13;
if (rot13>='N' &&rot13<='Z' )
rot13-=13;
if (rot13>='n' &&rot13<='z' )
rot13-=13;
Last edited on Feb 9, 2017 at 3:25pm UTC
Feb 9, 2017 at 3:50pm UTC
that looks correct. what exactly does it not do?
Feb 9, 2017 at 4:04pm UTC
It doesn't translate to rot13. it just prints what is in the file.
Feb 9, 2017 at 4:14pm UTC
the problem isnt the code you posted. your bug is something else in your program, like printing the original file instead of the new output.
add
cout << rot13 <<;
after all the if statements above.
is that output translated correctly?
Last edited on Feb 9, 2017 at 4:16pm UTC
Feb 9, 2017 at 4:24pm UTC
I added the cout<<rot13 and found that the loop works. So it looks like i'm printing the old file instead of new file.
Last edited on Feb 9, 2017 at 4:51pm UTC
Feb 9, 2017 at 4:26pm UTC
instead of cout << rot13 you need
outfile << rot13 I think, then open and check the output file in a text editor.