I'm attempting to write alil function here which basically reads from a string. It reads every three characters and evaluates it using the pre-condition (if statement). If conditions are met, it would replace those three letters with new three letters. Then it would output the new string.
I tried writing the code but cant seem to get the logic right. the program runs but it doesn't print out anything. Dont mind the function name and the inaccuracy. I'm just doing a sample function to test this out.
string amino_acids(string line) { string acid; string acids; string newline; for( int i= 0; i < line.length(); i++) { acid = line[i]; } for (int i = 0; i < 3; i++) { acids = acid[i]; if(acids == "GUU") { acids = "ZAP"; } newline = acids; } cout << "Acids: " <<newline <<endl; return newline; }
forloop to be inside the first one, among other things.for( int i= 0; i < line.length(); i++) { acid = line[i]; }is equivalent toif (!line.empty()) acid = line.back();. Is that what you intended?ifinside theforloop doesn't seem to make any sense. Why would you want to repeat thatiftest 3 times?