-4
        cout << "---------------------------------------------------\n";
        cout << "# Level:" << getLevel() << "                                         #\n";
        cout << "# Max Hp:" << getMaxHp() << "                                    #\n";
        cout << "# Hp:" << getHp() << "                                          #\n";
        cout << "# Attack Point:" << getAtkPoint() << "                               #\n";
        cout << "# Defense:" << getDefense() << "                                     #\n";
        cout << "---------------------------------------------------\n";

I wanted to do something like this but when number of digit of return value is more than 1 there will be a unwanted space

int sBasamak(int b)
{
int a=0;
while(b > 0)
{
    a++;
    b /= 10;    
}
return a;
}

This is what I did for keeping number of digits but the other part of solution is beyond my wisdom, hope you understand what I want to try.

EDIT:(IF ANYONE WONDER HERE HOW I FIXED IT)

void space(int b,char gelen[])
{   
int a=0;

while(b >0)    {
    a++;
    b /= 10;

}

int c=0;

for(int i=0 ; gelen[i] ; i++)
{
    c++;
}

cout << setw(51-c-a) << "#\n";

}

and

        int a=getLevel();
        int b=getMaxHp();
        int c=getHp();
        int d=getAtkPoint();
        int e=getDefense();
        cout << "---------------------------------------------------\n";
        cout << "# Level:" << a ; space(a," Level:");
        cout << "# Max Hp:" << b; space(b," Max Hp:"); 
        cout << "# Hp:" << c;  space(c," Hp:");
        cout << "# Attack Point:" << d;  space(d," Attack Point:");
        cout << "# Defense:" << e;  space(e," Defense:");
        cout << "---------------------------------------------------\n";

1 Answers1

-1

If your problem is that you want your '#'-es aligned, then I would recommend one of two things:

  1. use tabs(\t) instead of spaces (automatically allignes itself), or
  2. use a simple bit of logic (such as if(n>=10)cout<</*x spaces*/;else cout<x-1 spaces/;)

Hope this helps.

EDIT: Alternatively, you could output an ascii backspace. Not sure how well that works though.

Mark Gardner
  • 442
  • 1
  • 6
  • 18