You need to print :
for each strength point and fill the remaining with spaces (capacity). There are several methods.
Method 1: The loop
cout << '{';
for (unsigned int i = 0; i < capacity; ++i)
{
if (i < strength)
{
cout << ':';
}
else
{
cout << ' ';
}
}
Method 2: String of repeated characters
const std::string strength_text(strength, ':');
const std::string filler_text(capacity-strength, ' ');
cout << '{';
cout << strength_text << filler_text;
cout << '}';
Method 3: Setting field width
const std::string strength_text(strength, ':');
cout << '{';
cout << setw(capacity) << strength_text;
cout << '}';
You should research the setw
modifier to see if it performs a right justified or left justified fill.
Other methods involve cursor positioning, which requires an external library.
0
solved C++ How to make text health bar