So I'm, trying to code a program that codes your message into a secret one. My problem in this code is that it crashes in the for loop. So the program asks you to type your message then it goes in the for loop. I want to cout "it works" to see if there is a bug or something and yes indeed there's one. Sorry, I'm still very new in programming. I will appreciate your help to locate my error and explain to me why this is happening. Thanks in advance!
Try defining your message as a string in line 18 instead (because you don't know how big it is going to be, and a string is a container, which can expand as necessary): string message;
Although it would then "work" as is, I suggest you change your loop to
1 2 3 4
for (int index = 0; index < message.size(); index++ )
{
cout << "it worked" << endl;
}
Your cryptography will later replace line 25 in the loop.
Thanks for the help lastchance! Yeah, with a string I don't need to reserve space. I forgot about that. But now I'm facing another challenge! I want the for loop to go over each character in [code]string message[\code] in a switch statement. There will be a list of codes with that character.
for example:
[code]
switch(message)
{
case 'a': codedmessage = codedmessage + "JsDvdr9p"
break;
case 'b': codedmessage = codedmessage + "vK5PMXv7"
break;
//and so on
[\code]
With an array, I can point between brackets but not with strings. Do I use pointers or something?