I'm getting an error from this function, "control may reach end of non-void function" So how Would I go about and fix this. This is how I call the function gettability: tie(action, mana) = getability(pclass, mana, inte, level);
its saying that if all the possible else if combos fail, you don't have a final default return statement. It could be that your code never has this problem; the compiler can't tell. It may be logically impossible for your code to not trip one of the conditions.
If you are sure you code always hits one condition, you can ignore it or add a bogus return statement to silence it. If it can have this issue, you need a valid return code for that condition and a way to handle it elsewhere in the code (probably?).
warning, your code is looking too hard coded for any sort of re-use or maintainable design.
Why do you need so many return statements? As far as I can see they are all return {ability,mana}
so you can simply put that single return at the end, outside all the if blocks.
mana comes in as an argument, but you would need some default ability.
// Displays the abilities
pair<string, int> getability(string pclass, int mana, int inte, int level) {
string input;
string ability = "unknown"; // set default ability
int cost;
cout << "Choose an ability" << endl;
if (pclass == "Champion") { // Champion Section
cost = inte*(level);
cout << "[1] Cleaving Strike [" << cost << " mana]" << endl;
cout << "[2] Melting Thrust [" << cost << " mana]" << endl;
cout << "[3] Critical Bash [" << cost << " mana]" << endl;
cost = inte*(level+1);
cout << "[4] Purify [" << cost << " mana]" << endl;
cost = inte*(level);
cin >> input;
if (input == "1") {
ability = "cleaving strike";
if (mana > cost) {
mana = mana - cost;
}
} elseif (input == "2") {
ability = "melting thrust";
if (mana > cost) {
mana = mana - cost;
}
} elseif (input == "3") {
ability = "critical bash";
if (mana > cost) {
mana = mana - cost;
}
} elseif (input == "4") {
ability = "purify";
if (mana > cost) {
cost = inte*(level+1);
mana = mana - cost;
}
}
}
return {ability, mana};
}
Notice line 4. If you should ever see the ability value "unknown" appear after calling the function, you would need to investigate the cause. At present, that situation is not handled at all and would quite likely cause a program crash.