I have some code like:
#include <iostream>
#include <string>
int main() {
std::string question;
std::getline(std::cin, question);
if (question == "yes") {
std::cout << "Let's rock and roll!" << std::endl;
return 0; // This line
} if (question == "no") {
std::cout << "Too bad then..." << std::endl;
} else {
std::cout << "What do you mean by that?" << std::endl;
}
return 0;
}
If I don't write the commented return 0 line and input yes, the output is Let's rock and roll! followed by What do you mean by that?. It should only output Let's rock and roll!.
But I don't need to put return 0 in the if (question=="no"){...} block. If I input no, the output is just Too bad then....
Why do I need the return 0 in the first case, but not the second?