Need help outputting things from different functions (C++) -
i new c++ , coding in general. trying make basic little multiple choice type game practice have run conundrum.
the program isn't outputting want too. here code:
#include <iostream> #include <cstdlib> #include <ctime> #include <string> using namespace std; void sword(int damage); void fists(int damage); static int enemyhealth = 250; int main() { srand(time(0)); string sof; //abreveation "sword or fists" cout << "you fighting mean bad guy. using sword, or fists?\n"; while (sof != "sword" && sof != "fists"){ cout << "please enter choice of either 'sword' or 'fists': "; cin >> sof; } cout << "okay! time fight! \n"; if (sof == "fists") { void fists(); } else if (sof == "sword") { void sword(); } else{ (null); } cout << "congratulations! have vanquished foul beast!\n"; system("pause"); } //this when user chooses 'sword' void sword(int damage = rand() % 100 + 50) { while (enemyhealth > 0){ cout << "you deal " << damage << " damage sharp sword. \n"; enemyhealth -= damage; } } //this when user chooses 'fists' void fists(int damage = rand() % 10 + 4) { while (enemyhealth > 0){ cout << "you deal " << damage << " damage womanly fists. \n"; enemyhealth -= damage; } }
the first part works fine, when enter choice of either "fists"
or "sword"
output is:
okay! time fight! congratulations! have vanquished foul beast!
but want output damage being done either fists or sword.
if that, amazing. thanks!
void fists();
declaration, not call, change fists();
, sword();
other things at:
- default parameters declared in function declaration before
main
(or move whole functions there) - default parameters in c++ evaluated once, 'hits' same in code
- local variable names not named in uppercase,
sof
looks loke#define
d constant or such.
Comments
Post a Comment