Thread: How to change the value of a user input to a next value?

  1. #1
    Registered User
    Join Date
    Nov 2015
    Posts
    2

    How to change the value of a user input to a next value?

    How do I make user input a set of text and using the text which has only alphabet letters
    1)how would I read the text and move each letter to the next changing the value of the text?
    For example the letter a would change to b and b would change to c etc.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I suggest that you focus on the "move each letter" part first, e.g., write a function:
    Code:
    char nextLetter(char c);
    You can hard code a test in your main function, e.g., looping over a string consisting of the entire English alphabet and calling nextLetter for each character.

    Consider what should happen for 'z' and 'Z'. Consider also that in ASCII and its derivatives, the letters of the English alphabet are contiguous in value, though this is not actually guaranteed, but maybe with such a simplifying assumption it would be fine.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2015
    Posts
    2
    I am currently trying to make a simple encryption program so I would need an array with the alphabet letters and another array to change the text to the different letters. The program will change the string entered and change each character to the next letter e.g 'a' would change to 'b' and 'd' would be 'e' etc. Can someone please help

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    So, have you tried starting with what I suggested? Once you have a working nextLetter function, you can then write another function that calls nextLetter, e.g.,
    Code:
    void encrypt(char *text);
    After you have these working, perhaps you could take another step to encrypt with a key, e.g., modify nextLetter and encrypt to:
    Code:
    char nextLetter(char c, int key);
    void encrypt(char *text, int key);
    where in the original version a key value of 1 was implied.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 05-09-2012, 07:21 AM
  2. How do i change the input?
    By iluvanimestyle in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2011, 09:20 PM
  3. change characters entered from user to all uppercase
    By bcianfrocca in forum C++ Programming
    Replies: 7
    Last Post: 11-06-2004, 01:39 PM
  4. how to make user text change color
    By DarkViper in forum Tech Board
    Replies: 4
    Last Post: 12-15-2002, 05:28 PM
  5. How can I change my user's status?
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-21-2002, 10:39 PM

Tags for this Thread