Changing a phrase into dashes

Hey there, I have made this piece of code to change

Travis is cool also
______ __ ____ ____

however it is just giving me big ____________________
1
2
3
4
5
6
7
8
9
10
string phrase = "Travis is cool also"
hyphenedPhrase = ""
string letters = "abcdefghijklmnopqrstuvwxyz";
for(int i=0;i<phrase.length();i++){ 
        for(int j = 0; j < letters.length(); j++){
            if(phrase[i] == letters[j]){
                hyphenedPhrase += "-";
            }
        }
    }
Well you don't have anywhere in the code that would put a " " in hyphened phrase. You could just add an if statement to the first for loop that checks if the current index is a " ", and if it's not then go to the second loop.

Also you don't account for uppercase letters in your 2nd loop. You could just use toupper or tolower and that would fix it.

Topic archived. No new replies allowed.