Why do people post code that doesn't compile? I don't understand...
player_attack and boss_attack return an int. 'boss_health, player_norm' is not an int.
I see 'goto'. I doubt you actually need it.
boss_attack(health) does, effectively, absolutely nothing. What you might want is
health = boss_attack(health);
call srand only once at the beginning of the program. Remove the calls in boss_attack and player_attack.
Find better learning resources.
By the way, "something is not working" is very vague. The plain fact, that your Code doesn't compile with a sane C++ Compiler would be a little more specific. Posting the error messages with your code would be optimal. (After you looked for the error, and googled the error message and still couldn't solve the problem).
If you actually are interested in making this program work and I hear from you again, I'll gladly help with the rest
You are passing your parameters by value, meaning that the functions receive a copy of the variable fed to it and changes made to those parameters in the function are not passed on. Also, you seem to be confused about what the comma operator does.
return health, boss_norm; is functionally equivalent to return boss_norm;
Since you don't do anything with the return values, it is hard to see the point of having them anyway.
You should only seed the random number generator once per program invocation.
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
usingnamespace std;
void boss_attack(int& health);
void player_attack(int& boss_health);
int main()
{
srand(static_cast<unsignedint>(time(0)));
int boss_health = 100;
int health = 100;
const string boss = "'Prepare to die.' - the boss";
const string menu = "\n What would you like to do now?";
const string choice_one = "\n1. Attack";
const string choice_two = "\n2. Defend";
const string choice_three = "\n3. Pass";
const string c_menu = "\nYour choice: ";
const string UI_MENU = menu + choice_one + choice_two + choice_three + c_menu;
cout << "\t\tWelcome to Battle Masters.\n";
cout << "\tYou can enter 'quit' at any time to exit the game.\n\n";
cout << "You have 100 health. You are about to fight a boss.\n";
cout << boss;
boss_attack(health);
while (health > 0 && boss_health > 0)
{
cout << UI_MENU;
string answer;
cin >> answer;
if (answer == "1" || answer == "attack" || answer == "Attack")
{
player_attack(boss_health);
boss_attack(health);
}
elseif (answer == "quit")
return 0;
else
cout << "Invalid input.\n";
}
if (health > 0 && health > boss_health)
cout << "\nYou came out ahead in this fight.\n";
else
cout << "\nThis is a sad state of affairs.\n";
}
void boss_attack(int& health)
{
int boss_norm = (rand() % 5) + 10;
cout << "\nThe boss attacks you for: " << boss_norm << " damage";
health -= boss_norm;
cout << "\nYou now have " << health << " health.";
}
void player_attack(int& boss_health)
{
int player_norm = (rand() % 5) + 15;
cout << "You hit the boss for: " << player_norm;
boss_health -= player_norm;
cout << "\nThe boss now has: " << boss_health << " health ";
}