DNA strand compliments

Write your question here.
Hello, I am trying to finish this problem I found on Rosalind, however my logic seems to be wrong on a particular part. The goal of the problem is to take a DNA strand and produce it's reverse compliment. That is for every 'A' in the strand there should be a 'G' and vice-versa and for each 'C' there should be a 'G'. The problem I'm having now is that the array I have created will give me my result but it's also giving me the original form along with some other unrecognized data. Anyone have pointers as to what I may be doing wrong here?
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
46
47
48
49
50
51
52
53
54
#include<fstream>
#include<iostream>
#include<string>

using namespace std;

int main ()
{
	char dna [1000];
	char rna [1000];
	
	int length;
	ifstream myfile;
	ofstream newfile;
	
	myfile.open("rosalind_revc.txt");
	newfile.open("example.txt");
	
	myfile >> dna;

	length = strlen(dna);


	for(int i = 0; i < length; i++)
	{
		if (dna[i] == 'A')
		{
			rna[i] = 'T';
		}
		if (dna[i] == 'T')
		{
			rna[i] = 'A';
		}
		if (dna[i] == 'C')
		{
			rna[i] = 'G';
		}
		if (dna[i] == 'G')
		{
			rna[i] = 'C';
		}
		
	}

	cout << rna;

	myfile.close();
	newfile.close();	


	system("pause");
	return 0;

}
Try replacing
cout << rna;
with
1
2
for (int i = 0; i < length; ++i)
    cout << rna[i];

and see if that's any better.
Ahh...much better thanks a bunch friend.
Topic archived. No new replies allowed.