Support Forums

Full Version: Switch Conditionals in Functions not working????
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey everbody

I am having a problem with a switch conditional which calls a function

The function is

Code:
char FUNC_RACE_GOOD();

it is declared in the switch conditional like this

Code:
case '1':  // Case for choosing the good alignment
    cout << "You have chosen to join the sides of good...\n\n";
    char FUNC_RACE_GOOD(); // Call the good race function
    
    break;

And end up here

Code:
char FUNC_RACE_GOOD() { // Function race good

    char RACE;

    cout << "----------------------------------\n";
    cout << "               Races\n";
    cout << "----------------------------------\n\n\n";
    cout << "1. Elf\n";
    cout << "2. Human\n";
    cout << "3. Dwarf\n";
    cout << "----------------------------------\n";
    cout << "Enter the corresponding digit for your race...\n\n";
    cout << "Race: \n";
    cin >> RACE;
// Not finished yet

but all it does it completely skip the whole function call and just ends the program

any help?
That's not how you call a function, you just use the name, no need to specify the return type when calling it, just do:
Code:
case '1':  // Case for choosing the good alignment
    cout << "You have chosen to join the sides of good...\n\n";
    FUNC_RACE_GOOD(); // Call the good race function
    
    break;
Not even sure how that compiled.
yeah when calling a function, its name() will suffice. no need to add the data type
Wouldn't you want the function to return something aswell?
The function would still return something, whether you choose to do anything with it is up to you. If you wanted the value that function returns you would just do:
Code:
char returned = FUNC_RACE_GOOD(); // Call the good race function, storing the return value in 'returned'