[THIS IS HW] - Printing things twice, only need once

As noted above, this is HW but I'm hoping someone could help me find out what I'm doing wrong?

My entire code is posted below but my problem is that I seem to be printing out the "cout << "This is the similarity_score value inside my calcSimilarity(): " << similarity_score << endl;" portion twice when I only need it to print out once.

This part of the code is supposed to take in two separate DNA string sequences (i.e. "GCCGCCGT" and "GCCGCCGA", compare their lengths, find any mismatches between each indexed position, then go into some arithmetic to find their "similarity score". Once that is calculated, it should return that float value for later use.


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
#include <iostream>
#include <string>
using namespace std;

float calcSimilarity(string sequenceOne, string sequenceTwo)
{
        //get string length of each sequence
        float seqOneLength = sequenceOne.length();
        float seqTwoLength = sequenceTwo.length();
        float counter = 0;
        if ((seqOneLength > 1) && (seqOneLength == seqTwoLength))
            {
            for (int index = 0; index < seqOneLength; index++)
                {
                if (sequenceOne[index] != sequenceTwo[index])
                    counter = counter + 1;
                }
            //test cout statement to make sure counter actually stored mismatches
            //cout << counter << endl;
            float similarity_score = ((seqOneLength - counter)/seqTwoLength);
            //test cout statement to make sure similarity_score value is correct
            cout << "This is the similarity_score value inside my calcSimilarity(): " << similarity_score << endl;
            return similarity_score;
            }

return 0;
}

int main(){

string sequenceOne, sequenceTwo;
cout << "Enter sequence One" << endl;
cin >> sequenceOne;
cout << "Enter sequence Two" << endl;
cin >> sequenceTwo;

if ((sequenceOne.length() > 1) && (sequenceOne.length() == sequenceTwo.length()))
    {
    while ((sequenceOne.length() > 1) && (sequenceOne.length() == sequenceTwo.length()))
        {
        float stated = calcSimilarity(sequenceOne, sequenceTwo);
        calcSimilarity(sequenceOne, sequenceTwo);
        cout << "This is the similarity_score value inside my main(): " << stated << endl;
            cout << "Enter sequence One" << endl;
            cin >> sequenceOne;
            cout << "Enter sequence Two" << endl;
            cin >> sequenceTwo;
        }
    }
return 0;
}
Last edited on
delete line 11 , line 37 , line 42:

redundant code
Last edited on
Thank you!!
Topic archived. No new replies allowed.