Hi I have an array that is the alphabet (in alphabetical order) and i wanted to know how move a string (that is inputed) one to the right in my array then output it
Thank you
A char is just a small int, so you can increment it. Loop through your string, increment each char in it. You can use the [ ] operator just like an array to access each char. Might need an if statement if you want z to become a
int main() {
int x;
string newMessage;
cout << "What will you like your coded message to say? (write everything in lower case)\n";
getline(cin, message);
for (x = 0; x < message.length(); x++) {
int linearSearch = 0;
char result;
result = linearSearch;
if (result == char()) {
while (message.length()) {
//this is where i want to increment
}
cout << "This is your new message " << newMessage;
}
else {
cout << "Please try again.";
}
}
return 0;
};
// this will check for chars
int linearSearch(){
long size = message.length();
for (char index = 0; index < size; index++) {
bool message(true);
if (message == arrayLower[index])
return index;
#include <iostream>
#include <string>
#include <iomanip>
int main()
{
const std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ;
const std::string shifted_alphabet = "BCDEFGHIJKLMNOPQRSTUVWXYZAbcdefghijklmnopqrstuvwxyza" ;
const std::string message = "Hello World!" ; // message entered by the user
std::string new_message ;
// http://www.stroustrup.com/C++11FAQ.html#forfor( char c : message ) // for each character c in message
{
// find the position of the character in the alphabet
// http://www.cplusplus.com/reference/string/string/find/constauto pos = alphabet.find(c) ;
// if it was found, add the corresponding character in shifted_alphabet
if( pos != std::string::npos ) new_message += shifted_alphabet[pos] ;
else new_message += c ; // otherwise, add the character unchanged
}
// http://en.cppreference.com/w/cpp/io/manip/quoted (C++14)
std::cout << " message: " << std::quoted(message) << '\n'
<< "new message: " << std::quoted(new_message) << '\n' ;
}