I'm trying to create a for loop that loops through a string of chars imputed by the user and i want it to cout<< the arrayor string of chars three characters at a time.
like if i had "aaaaagggggtttttt" i want it to print "aaa" "aag" "ggg" etc. how do I do this?
I tried Googling it but I cant find an example
here's my code
#include<iostream>
#include<fstream>
#include <string>
usingnamespace std;
int main()//declaring 1st sub-function
{
//declaration of DNA & RNA Array
char DNA[50];
char RNA[50];
//User prompt
cout<<"Enter DNA Sequence"<<endl;
int len=0;//declaration and initialization of length counter
cin>>DNA;//user input to DNA Array
for(int i=0; i<=sizeof(DNA); i++){//for loop (initialized; Range; increment)
//the following if statements are the actual transcription
if (DNA[i] == 'A')
{cout<<"U";
RNA[i]='U';
len++;
}
if (DNA[i] == 'G')
{cout<<"C";
RNA[i]='C';
len++;
}
if (DNA[i] == 'C')
{cout<<"G";
RNA[i]='G';
len++;
}
if (DNA[i] == 'T')
{cout<<"A";
RNA[i]='A';
len++;
}
}
cout<<endl;
for(int i=0; i<len; i++){//this for loop uses the len variable to count & store value & amount of characters
cout<<RNA[i];//printing the next available character stored in the RNA array.
}
system("PAUSE");
return 0;
}
this part of the code this loop i want it to cout<< 3 characters at a time
1 2
for(int i=0; i<len; i++){//this for loop uses the len variable to count & store value & amount of characters
cout<<RNA[i];//printing the next available character stored in the RNA array.