Hello

I'm trying to make a simple function to Rot13 strings and it's not working.I ran it through my debugger and it works until it get to the top of the loop again???Then some of the chars are rot13ed and some stay the same.

void Rot13(std::string &buffer)
{
    int inc;
    
    for(inc = 0;buffer[inc] != '\0';inc++)
    {
        if(buffer[inc] >= 'a' && buffer[inc] <= 'z')
        {
            if(buffer[inc] < 'n')
            {
                buffer[inc] += 13;
            }
            
            if(buffer[inc] >= 'n')
            {
                buffer[inc] -= 13;
            }
        }
        
        if(buffer[inc] >= 'A' && buffer[inc] <= 'Z')
        {
            if(buffer[inc] < 'N')
            {
                buffer[inc] += 13;
            }
            if(buffer[inc] >= 'N')
            {
                buffer[inc] -= 13;
            }
        }
        
        else
        {
            continue;
        }
    }
}
void Rot13(std::string &buffer)
{
    int inc;
    
    for(inc = 0;buffer[inc] != '\0';inc++)
    {
        if(buffer[inc] >= 'a' && buffer[inc] <= 'z')
        {
            if(buffer[inc] < 'n')
            {
                buffer[inc] += 13;
            }
            
            else
            {
                buffer[inc] -= 13;
            }
        }
        
        else if(buffer[inc] >= 'A' && buffer[inc] <= 'Z')
        {
            if(buffer[inc] < 'N')
            {
                buffer[inc] += 13;
            }
            else
            {
                buffer[inc] -= 13;
            }
        }
    }
}

Thank you :)


LOL I need to go relearn my C\C++ Ifs

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.