Hi, I've been doing C++ for about 2 hours now, so please don't confuse me much, i've been working on a small game to test variables and loops. I've got a woking script for now, but am stuck with the integers of a and x updating when both the character and enemy receive damage. I can do it manualy by adding more loops where with each hit, it forces the integers a and x to change, but for when I want to get more into it and add potions, exp gaining and stat boosting it will be a whole load of loops and will eventually get too confusing for me. So can someone let me know of how I can get integers a and x to continiously updates each time they receive damage, thanks.
Code:#include <iostream> #include <string> int subtract(int x, int y) { return x-y; } int subtracta(int x, int z) { return x-z; } int subtractb(int a, int b) { return a-b; } int subtractc(int a, int c) { return a-c; } using namespace std; int main() { int x(100), y(5), z(10), a(10), b(5), c(2); string answer; for (int (x < 100); int (x > 0); x){ cout<<"would you like to hit or block the enemy? "; cin>>answer; if (answer=="hit") { cout<<"you have hit the enemy\n"; cout<<"the enemy has "<<subtractb(a, b)<<" hp\n"; cout<<"your hp is now "<<subtracta(x, z)<<"\n"; } else if (answer=="block"){ cout<<"the enemy has hit you\n"; cout<<"the enemy has "<<subtractc(a, c)<<" hp\n"; cout<<"your hp is now "<<subtract(x, y)<<"\n"; } else { cout<<"you can only hit or block, try again\n"; } cin.get(); } }



LinkBack URL
About LinkBacks




