My code is not executing anything after the for loop












1














I am having a problem with a test project in a visual studio.
From my understanding, the problem comes from the function 'yeet'.

The function does not finish the loop, since it does not print out "why!!" .



Could someone help me in identifying what is wrong with my code?



Here is my code





string reet(char reet) {
switch (reet) {
case 'a':
return "Zg";
break;
case'b':
return "dA";
break;
case 'c':
return "dG";
break;
case 'd':
return "aw";
break;
case 'e':
return "bw";
break;
case 'f':
return "dQ";
break;
case 'g':
return "cg";
break;
case 'h':
return "ZA";
break;
case 'i':
return "cQ";
break;
case 'j':
return "YQ";
break;
case 'k':
return "eA";
break;
case 'l':
return "dw";
break;
case 'm':
return "cw";
break;
case 'n':
return "ag";
break;
case 'o':
return "eQ";
break;
case 'p':
return "bA";
break;
case 'q':
return "aA";
break;
case 'r':
return "ZQ";
break;
case 's':
return "cA";
break;
case 't':
return "aw";
break;
case 'u':
return "eg";
break;
case 'v':
return "bg";
break;
case 'w':
return "aq";
break;
case 'x':
return "bQ";
break;
case 'y':
return "Yg";
break;
case 'z':
return "Zw";
break;
}
}


void yeet(string input) {
string yeet = input;
string bigBoi = "";
int yeetL = yeet.length() + 1;
for (int x = 0; x < yeetL;) {
bigBoi = bigBoi + reet(yeet[x]);
x++;
cout << bigBoi << endl;
}
cout << "why!" << endl;
}

int main() {
string input;
cin >> input;
yeet(input);
}




For further Information, I am Using C++ on Microsoft Visual Studio 2013.










share|improve this question
























  • What input are you entering? reet does not return a value in all cases.
    – Johnny Mopp
    Nov 12 at 21:07






  • 1




    On the last iteration of the loop, you call reet(yeet[yeet.length()]). Here, yeet[yeet.length() is the character - the terminating NUL character. reet('') exhibits undefined behavior, by way of non-void function reaching the closing brace without encountering a return statement. In fact, depending on user input, it's possible you hit this case of undefined behavior sooner; but you definitely hit it on the last iteration regardless.
    – Igor Tandetnik
    Nov 12 at 21:09








  • 2




    Which is why you should: 1. Use std::string::at instead as it will throw a std::out_of_range exception. 2. Enable all compiler warnings which should tell you that not all paths return a value.
    – Johnny Mopp
    Nov 12 at 21:14












  • Ok, adding a default case worked. Thank you for helping!!
    – NipIsTrue
    Nov 12 at 22:53






  • 1




    You can also consider std::map<char, std::string> mp{{'a',"str1"},{'b',"str2"}} -> mp['a'] prints "str1"
    – Barmak Shemirani
    Nov 12 at 23:42


















1














I am having a problem with a test project in a visual studio.
From my understanding, the problem comes from the function 'yeet'.

The function does not finish the loop, since it does not print out "why!!" .



Could someone help me in identifying what is wrong with my code?



Here is my code





string reet(char reet) {
switch (reet) {
case 'a':
return "Zg";
break;
case'b':
return "dA";
break;
case 'c':
return "dG";
break;
case 'd':
return "aw";
break;
case 'e':
return "bw";
break;
case 'f':
return "dQ";
break;
case 'g':
return "cg";
break;
case 'h':
return "ZA";
break;
case 'i':
return "cQ";
break;
case 'j':
return "YQ";
break;
case 'k':
return "eA";
break;
case 'l':
return "dw";
break;
case 'm':
return "cw";
break;
case 'n':
return "ag";
break;
case 'o':
return "eQ";
break;
case 'p':
return "bA";
break;
case 'q':
return "aA";
break;
case 'r':
return "ZQ";
break;
case 's':
return "cA";
break;
case 't':
return "aw";
break;
case 'u':
return "eg";
break;
case 'v':
return "bg";
break;
case 'w':
return "aq";
break;
case 'x':
return "bQ";
break;
case 'y':
return "Yg";
break;
case 'z':
return "Zw";
break;
}
}


void yeet(string input) {
string yeet = input;
string bigBoi = "";
int yeetL = yeet.length() + 1;
for (int x = 0; x < yeetL;) {
bigBoi = bigBoi + reet(yeet[x]);
x++;
cout << bigBoi << endl;
}
cout << "why!" << endl;
}

int main() {
string input;
cin >> input;
yeet(input);
}




For further Information, I am Using C++ on Microsoft Visual Studio 2013.










share|improve this question
























  • What input are you entering? reet does not return a value in all cases.
    – Johnny Mopp
    Nov 12 at 21:07






  • 1




    On the last iteration of the loop, you call reet(yeet[yeet.length()]). Here, yeet[yeet.length() is the character - the terminating NUL character. reet('') exhibits undefined behavior, by way of non-void function reaching the closing brace without encountering a return statement. In fact, depending on user input, it's possible you hit this case of undefined behavior sooner; but you definitely hit it on the last iteration regardless.
    – Igor Tandetnik
    Nov 12 at 21:09








  • 2




    Which is why you should: 1. Use std::string::at instead as it will throw a std::out_of_range exception. 2. Enable all compiler warnings which should tell you that not all paths return a value.
    – Johnny Mopp
    Nov 12 at 21:14












  • Ok, adding a default case worked. Thank you for helping!!
    – NipIsTrue
    Nov 12 at 22:53






  • 1




    You can also consider std::map<char, std::string> mp{{'a',"str1"},{'b',"str2"}} -> mp['a'] prints "str1"
    – Barmak Shemirani
    Nov 12 at 23:42
















1












1








1







I am having a problem with a test project in a visual studio.
From my understanding, the problem comes from the function 'yeet'.

The function does not finish the loop, since it does not print out "why!!" .



Could someone help me in identifying what is wrong with my code?



Here is my code





string reet(char reet) {
switch (reet) {
case 'a':
return "Zg";
break;
case'b':
return "dA";
break;
case 'c':
return "dG";
break;
case 'd':
return "aw";
break;
case 'e':
return "bw";
break;
case 'f':
return "dQ";
break;
case 'g':
return "cg";
break;
case 'h':
return "ZA";
break;
case 'i':
return "cQ";
break;
case 'j':
return "YQ";
break;
case 'k':
return "eA";
break;
case 'l':
return "dw";
break;
case 'm':
return "cw";
break;
case 'n':
return "ag";
break;
case 'o':
return "eQ";
break;
case 'p':
return "bA";
break;
case 'q':
return "aA";
break;
case 'r':
return "ZQ";
break;
case 's':
return "cA";
break;
case 't':
return "aw";
break;
case 'u':
return "eg";
break;
case 'v':
return "bg";
break;
case 'w':
return "aq";
break;
case 'x':
return "bQ";
break;
case 'y':
return "Yg";
break;
case 'z':
return "Zw";
break;
}
}


void yeet(string input) {
string yeet = input;
string bigBoi = "";
int yeetL = yeet.length() + 1;
for (int x = 0; x < yeetL;) {
bigBoi = bigBoi + reet(yeet[x]);
x++;
cout << bigBoi << endl;
}
cout << "why!" << endl;
}

int main() {
string input;
cin >> input;
yeet(input);
}




For further Information, I am Using C++ on Microsoft Visual Studio 2013.










share|improve this question















I am having a problem with a test project in a visual studio.
From my understanding, the problem comes from the function 'yeet'.

The function does not finish the loop, since it does not print out "why!!" .



Could someone help me in identifying what is wrong with my code?



Here is my code





string reet(char reet) {
switch (reet) {
case 'a':
return "Zg";
break;
case'b':
return "dA";
break;
case 'c':
return "dG";
break;
case 'd':
return "aw";
break;
case 'e':
return "bw";
break;
case 'f':
return "dQ";
break;
case 'g':
return "cg";
break;
case 'h':
return "ZA";
break;
case 'i':
return "cQ";
break;
case 'j':
return "YQ";
break;
case 'k':
return "eA";
break;
case 'l':
return "dw";
break;
case 'm':
return "cw";
break;
case 'n':
return "ag";
break;
case 'o':
return "eQ";
break;
case 'p':
return "bA";
break;
case 'q':
return "aA";
break;
case 'r':
return "ZQ";
break;
case 's':
return "cA";
break;
case 't':
return "aw";
break;
case 'u':
return "eg";
break;
case 'v':
return "bg";
break;
case 'w':
return "aq";
break;
case 'x':
return "bQ";
break;
case 'y':
return "Yg";
break;
case 'z':
return "Zw";
break;
}
}


void yeet(string input) {
string yeet = input;
string bigBoi = "";
int yeetL = yeet.length() + 1;
for (int x = 0; x < yeetL;) {
bigBoi = bigBoi + reet(yeet[x]);
x++;
cout << bigBoi << endl;
}
cout << "why!" << endl;
}

int main() {
string input;
cin >> input;
yeet(input);
}




For further Information, I am Using C++ on Microsoft Visual Studio 2013.







c++ visual-c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 at 3:58









Bandi Kishore

3,3341730




3,3341730










asked Nov 12 at 21:02









NipIsTrue

196




196












  • What input are you entering? reet does not return a value in all cases.
    – Johnny Mopp
    Nov 12 at 21:07






  • 1




    On the last iteration of the loop, you call reet(yeet[yeet.length()]). Here, yeet[yeet.length() is the character - the terminating NUL character. reet('') exhibits undefined behavior, by way of non-void function reaching the closing brace without encountering a return statement. In fact, depending on user input, it's possible you hit this case of undefined behavior sooner; but you definitely hit it on the last iteration regardless.
    – Igor Tandetnik
    Nov 12 at 21:09








  • 2




    Which is why you should: 1. Use std::string::at instead as it will throw a std::out_of_range exception. 2. Enable all compiler warnings which should tell you that not all paths return a value.
    – Johnny Mopp
    Nov 12 at 21:14












  • Ok, adding a default case worked. Thank you for helping!!
    – NipIsTrue
    Nov 12 at 22:53






  • 1




    You can also consider std::map<char, std::string> mp{{'a',"str1"},{'b',"str2"}} -> mp['a'] prints "str1"
    – Barmak Shemirani
    Nov 12 at 23:42




















  • What input are you entering? reet does not return a value in all cases.
    – Johnny Mopp
    Nov 12 at 21:07






  • 1




    On the last iteration of the loop, you call reet(yeet[yeet.length()]). Here, yeet[yeet.length() is the character - the terminating NUL character. reet('') exhibits undefined behavior, by way of non-void function reaching the closing brace without encountering a return statement. In fact, depending on user input, it's possible you hit this case of undefined behavior sooner; but you definitely hit it on the last iteration regardless.
    – Igor Tandetnik
    Nov 12 at 21:09








  • 2




    Which is why you should: 1. Use std::string::at instead as it will throw a std::out_of_range exception. 2. Enable all compiler warnings which should tell you that not all paths return a value.
    – Johnny Mopp
    Nov 12 at 21:14












  • Ok, adding a default case worked. Thank you for helping!!
    – NipIsTrue
    Nov 12 at 22:53






  • 1




    You can also consider std::map<char, std::string> mp{{'a',"str1"},{'b',"str2"}} -> mp['a'] prints "str1"
    – Barmak Shemirani
    Nov 12 at 23:42


















What input are you entering? reet does not return a value in all cases.
– Johnny Mopp
Nov 12 at 21:07




What input are you entering? reet does not return a value in all cases.
– Johnny Mopp
Nov 12 at 21:07




1




1




On the last iteration of the loop, you call reet(yeet[yeet.length()]). Here, yeet[yeet.length() is the character - the terminating NUL character. reet('') exhibits undefined behavior, by way of non-void function reaching the closing brace without encountering a return statement. In fact, depending on user input, it's possible you hit this case of undefined behavior sooner; but you definitely hit it on the last iteration regardless.
– Igor Tandetnik
Nov 12 at 21:09






On the last iteration of the loop, you call reet(yeet[yeet.length()]). Here, yeet[yeet.length() is the character - the terminating NUL character. reet('') exhibits undefined behavior, by way of non-void function reaching the closing brace without encountering a return statement. In fact, depending on user input, it's possible you hit this case of undefined behavior sooner; but you definitely hit it on the last iteration regardless.
– Igor Tandetnik
Nov 12 at 21:09






2




2




Which is why you should: 1. Use std::string::at instead as it will throw a std::out_of_range exception. 2. Enable all compiler warnings which should tell you that not all paths return a value.
– Johnny Mopp
Nov 12 at 21:14






Which is why you should: 1. Use std::string::at instead as it will throw a std::out_of_range exception. 2. Enable all compiler warnings which should tell you that not all paths return a value.
– Johnny Mopp
Nov 12 at 21:14














Ok, adding a default case worked. Thank you for helping!!
– NipIsTrue
Nov 12 at 22:53




Ok, adding a default case worked. Thank you for helping!!
– NipIsTrue
Nov 12 at 22:53




1




1




You can also consider std::map<char, std::string> mp{{'a',"str1"},{'b',"str2"}} -> mp['a'] prints "str1"
– Barmak Shemirani
Nov 12 at 23:42






You can also consider std::map<char, std::string> mp{{'a',"str1"},{'b',"str2"}} -> mp['a'] prints "str1"
– Barmak Shemirani
Nov 12 at 23:42



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270054%2fmy-code-is-not-executing-anything-after-the-for-loop%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270054%2fmy-code-is-not-executing-anything-after-the-for-loop%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)