I decieded to make a program that translates a phrase in english to "1337" or "elite". I have searched this website and others and can't find an answer to the error I'm getting. Thanks for any help :).

Btw I'm using Bloodshed Dev C++, not sure if that matters.

/*
Author: Cclausen7
Date: 10/15/10
Purpose: English to Elite
*/

#include <iostream>
#include <string>
#include <cstring>

using namespace std;

//Function Declarations
void enterGameLoop();
string askWord(string prompt);
string convertWord(string word);

//Global Variable Declarations
string word = " ";
string again = "n";

//Array declaration
string alphabet= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string leet[26]={"4","13","(","D","E","pH","9","|-|","1","j","|<","L","/\\/\\","|\\|","0","P","Q","R","5","7","|_|","\\/","\\/\\/","><","Y","2"};


int main()
{
    //Changes text color to look more awesome
    system("color 02");
    
    //Enters the main game loop for the program
    enterGameLoop();
    
    return 0;
}

void enterGameLoop()
{
     do
    {
    //Asks for a word form the user
    word = askWord("\n\nEnter a word/phrase below\n\n>");
    
    //Converts e's to 3's
    word = convertWord(word);
    
    //Displays converted word and asks if they want to go again
    cout << word << "\n\nThe size of the word/phrase is " << word.size() << " characters\n\nDo you want to enter another word y/n?\n\n>";
    
    getline(cin,again);
    }
    while(again == "y");
}

string askWord(string prompt)
{
       system("CLS");
       
       string word;
       
       cout << prompt;
       
       getline(cin,word);
       
       cout << "\n\n" << word << " -> ";
       
       return word;
}

string convertWord(string word)
{
      for(int counter=0; counter < word.size(); counter++)
      {
              for(int i; i < 26; i++)
              {         
                      if (word[counter] == alphabet[i])
                    {
                                        word[counter] = leet[i];
                    }
              }
      }
      
      return word;                    
}
string convertWord(string word)
{
      for(int counter=0; counter < word.size(); counter++)
      {
              for(int i; i < 26; i++)
              {
                      if (word[counter] == alphabet[i])
                    {
                                        word[counter] = leet[i];
                    }
              }
      }

      return word;
}

You are trying to put in a string in-place of a character. That cannot be done.

And secondly the value of variable 'i' is not set to zero. So it might force the loop not to occur in the first place.

Why did you include <string> AND <cstring>?

Thanks a lot for the help guys, ixmike88's use of replace worked great, except for one thing. The program runs without compile errors and will translate most of the letters fine, but if you enter a longer word it will not translate some of the word, the program just leaves it out.

For example, if I enter "Minnesota" into the translator, it returns "/\/\E$074". The "i" and two "n"s are left out completely. Is this caused because "word.size()" changes when the M is translated to /\/\? Here is the code for the actual translation portion, as well as the string word and array leet, for reference.

string alphabet= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

string leet[52]={"4","B","(","D","E","pH","9","|-|","1","j","|<","L","/\\/\\","|\\|","0","P","Q","R","5","7","|_|","\\/","\\/\\/","><","Y","2","4","B","(","D","E","Ph","9","|-|","1","j","|<","L","/\\/\\","|\\|","0","P","Q","R","$","7","|_|","\\/","\\/\\/","><","Y","2"};


for(int i = 0; i < word.size(); i++)
      {
                 for(int j = 0; j < 52; j++)
                 {
                         if(word[i] == alphabet[j])
                         {
                                    word.replace(i, leet[j].size(), leet[j]);
                         }
                 }
      }

yes, you should probably make a new string for the output instead of using word

I got it to work fine, but I've got another idea >;). Could I use the std::transform() function to do this? I was looking at upper to lower conversion and vice versa and came across it. Here is the way I understand it, you have four arguments the std::transform accepts, the start and end of your word are the first two, the third is the beginning of your word again (if your overriding it, which I think I would want to). What I need help with is the fourth argument the, the uh unary operator. I still don't fully understand what that is, the stuff on the sites I normally look at look like gibberish to me >.<, so I'm hoping you guys can help me understand that better.

Also, I would like to know what I would need to put in the fourth argument to replace the alphabet with the 1337.

Thanks! You guys are the best!

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.