Skip to content

Instantly share code, notes, and snippets.

@aviralgoel
Created June 7, 2022 10:36
Show Gist options
  • Save aviralgoel/6f56cf2b2efd2d3977eaf38d6453465a to your computer and use it in GitHub Desktop.
Save aviralgoel/6f56cf2b2efd2d3977eaf38d6453465a to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
// Solution #1 (BAD)
int IncreaseHealthBy50(int _hp)
{
return _hp + 100;
}
int IncreaseHealthBy60(int _hp)
{
return _hp + 60;
}
// Solution #2 (Bad)
int IncreaseHealthBy(int _hp, int value)
{
return hp+value;
}
int main()
{
cout << IncreaseHealthBy50(100);
cout << IncreaseHealthBy60(200);
// Drawback: we have to pass 50 again and again explicitly
cout << IncreaseHealthBy(100, 50);
cout << IncreaseHealthBy(150, 50);
cout << IncreaseHealthBy(200, 50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment