I created a function which takes a string for a message and an input value (primarily an integer, at least in this case) so I can print a message and take an input in a single function instead of two lines of code. Here is the snippet:
main.h
void input(std::string msg, int choice) {
std::cout << msg;
std::cin >> choice;
}
However, when passing the function in my main function, it doesn't perform the same way this would:
main.cpp (working code with expected result)
int initial_choice;
std::cout << "Invalid input provided. Please try again: ";
std::cin >> initial_choice;
main.cpp (working code with unexpected result)
int initial_choice;
input("Invalid input provided. Please try again: ", initial_choice);
When it comes to the snippet with the expected result, my switch case function properly detects the input (in this case it is initial_choice) as a valid integer. For example, entering 1, 2, or 3 will work with case 1:, case 2:, and case 3:. However, the snippet with the unexpected result doesn't detect any of the three valid numbers in my switch case function, instead they all run the code under the default case.