#include <iostream>
usingnamespace std;
/*This will be a
random test for my own use*/
int main()
{
int steal;
int golds = 50;
int enemyGold = 2500;
int resultIng = golds + steal;
cout << "You have " << golds << " gold, while enemy have " << enemyGold << " gold" << endl;
cout << "How much do you want to steal?: " << endl;
cin >> steal;
cout << "You stole " << steal << " gold" << endl;
cout << "You now have " << resultIng << " gold" << endl;
cout << "Enemy have " << enemyGold - resultIng << endl;
cin.get();
cin.get();
return 0;
}
This is just a console command where I want to make the user "steal" money from the enemy
As you start with 50 Gold, and the enemy has 2500, I want you to be able to steal from him, after user input it shows you results how much you have now, how much you stole, and how much the enemy have
This is only a test for myself and not going anywhere, but I can't seem to fix the mistake in my code
The steal variable isn't initialised, so it contains a complete junk value. You're adding that to the result, making this more or less random.
Also, when you're stealing you want to make sure the value actually comes off the enemy's stash. This line isn't doing that: cout << "Enemy have " << enemyGold - resultIng << endl;
It's simply printing a temporary variable, created from the subtraction there.
I don't think you need the result variable at all. You could do this without it. Something like:
1 2 3 4 5 6 7 8 9 10
int gold = 50,
enemy_gold = 2500,
steal_amount = 0;
/* Code to get steal amount here */
gold += steal_amount;
enemy_gold -= steal_amount;
/* Print how much you have here */