Hello. I'm working on a simple game. I know this isn't advanced, or proper way to do this, but I'm just learning functions. That's where I need the help. Could you go over this code, and point out where the errors are?
#include <iostream>
#include <string>
usingnamespace std;
int Hero_Health, Damage, Remaining_Health;
int battle (int Hero_Health, int Damage int Remaining_Health);
int main ()
{
string Hero_Name;
string Answer;
cout << "What is your hero's name?: ";
getline(cin, Hero_Name);
cout << "Welcome " << Hero_Name << " You are walking in the hills of Talbis when you come across a vicious goblin. Do you wish to battle the creature, or run away? ";
getline(cin, Answer);
if (Answer == "battle him" || Answer == "fight him" || Answer == "fight" || Answer == "battle" || Answer == "f" || Answer == "b")
{
battle(100, 50, );
cout << "You draw out your sword, and advance on the creature! After exchanging blows you deal him damage. Your remaining health is: " << Remaining_Health;
}
else
{
cout << "You decide to run into the distance";
}
return 0;
}
int battle ( int Hero_Health, int Damage)
{
Hero_Health - Damage = Remaining_Health;
return Remaining_Health;
}
#include <iostream>
#include <string>
usingnamespace std;
int Hero_Health, Damage, Remaining_Health;
int battle (int Hero_Health, int Damage);
int main ()
{
string Hero_Name;
string Answer;
cout << "What is your hero's name?: ";
getline(cin, Hero_Name);
cout << "Welcome " << Hero_Name << " You are walking in the hills of Talbis when you come across a vicious goblin. Do you wish to battle the creature, or run away? ";
getline(cin, Answer);
if (Answer == "battle him" || Answer == "fight him" || Answer == "fight" || Answer == "battle" || Answer == "f" || Answer == "b")
{
battle(100, 50);
cout << "You draw out your sword, and advance on the creature! After exchanging blows you deal him damage. Your remaining health is: " << Remaining_Health;
}
else
{
cout << "You decide to run into the distance";
}
return 0;
}
int battle ( int Hero_Health, int Damage)
{
Hero_Health - Damage = Remaining_Health;
return Remaining_Health;
}
You have global variables Hero_Health, Damage, and Remaining_Health, but those aren't the same values being used in your function. Line 28 is still broken.
Global variables can't be used, and given a value anywhere within the program? I thought that Hero_Health, and Damage would be given values here.
battle(100, 50);
and then I thought that Remaining_Health would be given it's value here.
Hero_Health - Damage = Remaining_Health;
and then returned to here.
cout << "You draw out your sword, and advance on the creature! After exchanging blows you deal him damage. Your remaining health is: " << Remaining_Health;