How to Replace an Else-If Sequence with an Elegant Ternary Operator
fluentcpp.com
fluentcpp.com
Google Image search shows that it's a stock photograph, also used at http://orangenaturals.com/blog/teaching-positive-self-image/ ("Marci Warhaft is teaching young people how to love themselves"), http://www.inspiredlivingaffirmations.com/beauty-is-when-you... ("6 Ways To Feel Good About Your Body"), , http://horoscopean.com/heres-deal-heartbreak-based-zodiac-si... ("Here’s How You Deal With Heartbreak, Based On Your Zodiac Sign"), https://childrenandmediaman.com/2016/08/03/tween-girls-perce... ("Tween girls’ perceptions of the “just-right” body ideal and what it means for them socially"), and more.
That last link uses the photograph to illustrate the social pressure, including from media, for tween girls to look a certain way. In that context, its use now for a programming blog gives an example of how that social pressure may manifest itself.
As to the topic at hand, the code I would prefer is:
static inline char get_display_char(int x, int y)
{
if (x + y >= 30) return '.';
if (x + y >= 25) return '/';
if (x + y >= 20) return 'o';
if (x - 3*y > 0) return '|';
if (x - y > 0) return '\\';
return '_';
}
...
for (int y = 0; y < 20; ++y)
{
for (int x = 0; x < 20; ++x)
{
std::cout << get_display_char(x, y);
}
std::cout << '\n';
}