if statements

This is a discussion on if statements within the C++ Programming forums, part of the General Programming Boards category; O.k. I have to creat an if statement that will change one charechter to another for decoding. The key for ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    30

    if statements

    O.k. I have to creat an if statement that will change one charechter to another for decoding. The key for the decoding is in an array and everything else is setup. Here is what I have for my if statement:
    if (ch ==key[i][1])
    ch = key[i][0];

    The array is setup so that the new letter is in [i][0] and the original letter is in [i][1]. When ever I input a number it just returns the original letter. So for instnce if at the promp i input the letter b all that is returned is the letter b. Anybody know what is wrong with my if statement? Any help would be greatly appreciated.

  2. #2
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    I think you are going about that a little wrong, or thinking about it wrong at least.

    If you are reading one characer at a time, which i figure you are, here is an example.
    To change one letter to another, as in changing a to b, then this is what you want:
    Code:
    if((ch=='a')||(ch=='A'))
    {
         ch='b';  //or'B'
    }
    If this is not what you wanted, you need to explain yourself a little better.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    30
    What is going on is that there is a whole encoded message. I want it so that when you run the program it reads one charechter at a time in the encoded message. After it reads the charechter it should go to the if statement then change each charechter accordingly. Our teacher told us we had to set up the key in an array. Is it possible to change a charechter in an array to another charechter in an array? If not with an if statement is there another way to do it such as a function?
    Thanks for any help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 03:09 AM
  2. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  3. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  4. Class Function Members and If Statements
    By Team Shadow V2 in forum C++ Programming
    Replies: 10
    Last Post: 02-03-2005, 02:00 PM
  5. Switch statements for strings
    By cxs00u in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2002, 03:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21