Write your question here.
I must verify that a string of any length contain only valid characters:G,A,T,C. If any characters do not contain G or A or T or C keep asking the user for input until it is valid.
Once the DNA string is valid input it as the strand string for a variable of class dna:
This is the code in my main function where the user inputs the string that goes into the "dna" class and the ID of the DNA:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
for(int i=0;i<SIZE;i++){
cout<<" Please insert the ID of DNA sample: "<<i<<endl;
cin>>eyeD;
STRAND[i].seteyeD(eyeD);
cout<<" Please insert the strand for DNA sample "<<i<<endl;
cin>>sample;
do{
cout<<" Please REINSERT the strand for DNA sample "<<i<<endl;
cout<<"Must be G or A or T or C\n";
cin>>sample;
}
while(checkDNA(sample)==false);
STRAND[i].setsample(sample);
cout<<"STRAND "<<i<<" length:"<<STRAND[i].getsample().length()<<endl;
cout<<"STRAND "<<i<<" sample:"<<STRAND[i].getsample()<<endl;
dnaout <<STRAND[i].geteyeD()<<endl;
dnaout <<STRAND[i].getsample()<<endl;
}
|
This is the function that verifies that the initial string inputted by the user is valid. ie. It contain either G or A or T or C.
1 2 3 4 5 6 7 8 9 10 11
|
bool checkDNA(string strand){
bool check=true;
int SIZED=strand.length();
for (int i=0;i<SIZED-1;i++){
if ((strand.at(i) != 'A') && (strand.at(i) != 'T') && (strand.at(i) != 'G') && (strand.at(i) != 'C')){
check = false;
break;
}
}
return check;
}
|
I cannot get it to move on to displaying the ID and the strand of the DNA sample. It just declared the ID and Strand for all DNAs until the program closes on it's own.
Thanks to anyone who can help. I have tried everything I can to fix it and have tried many different ways recommended online for this sort of problem.
If anyone can fix with piece of code for me it would be greatly appreciated. This is the final project for my class and I have the functions for everything to work, I just need to ensure that the DNA strands are actually valid.
THANK YOU.