Program won't execute, and will not write to file (ROT13 Decoder Program)

I am having trouble with the program executing. It will compile successfully, but when I run it nothing happens and the program runs forever (it just fills the screen with |[|[|[|[|[|[|). Also, it won't write to the output file.



What is the Problem?



(I am using visual studio, and I have included the .txt files in the source)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
#include<fstream>


using namespace std;


int main(){
	char c=0;
	ifstream inputmessage;
	ofstream outputmessage;

	inputmessage.open("secretMessage.txt");
	outputmessage.open("decodedMessage.txt");

	
	inputmessage.get(c);
       while (!inputmessage.eof()){
               if (c>='a' && c<='m'){
				    c += 13;
				}else if (c >= 'n' && c <= 'z'){ 
					c -= 13;
				}else if (c >= 'A' && c <= 'M'){ 
					c += 13;
				}else if (c >= 'N' && c <= 'Z'){
					c -= 13;
				}
				cout<<c;
				inputmessage.get(c);
			}
		inputmessage.close();
		outputmessage.close();
return 0;
}
Last edited on
I ran your code, the only problem I had was no output in the decodedMessage file. That's just because there is no code to output the message to the file.

I made some changes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
#include<fstream>
#include <cstdlib>

using namespace std;


int main(){
	char c=0;
	ifstream inputmessage;
	ofstream outputmessage;

	inputmessage.open("secretMessage.txt");
	if (inputmessage.fail())
	{
		cout << "The input file has failed to open" << endl;
		cin.ignore();
		exit(1);
	}

	outputmessage.open("decodedMessage.txt");


	inputmessage.get(c);
	while (!inputmessage.eof()){
		if (c>='a' && c<='m'){
			c += 13;
		}else if (c >= 'n' && c <= 'z'){ 
			c -= 13;
		}else if (c >= 'A' && c <= 'M'){ 
			c += 13;
		}else if (c >= 'N' && c <= 'Z'){
			c -= 13;
		}
		cout<<c;
		outputmessage << c;
		inputmessage.get(c);
	}
	
	inputmessage.close();
	outputmessage.close();
	
	cin.ignore();
	return 0;
}
Topic archived. No new replies allowed.