# Dumb alignment

• 06-21-2004
cyberCLoWn
Dumb alignment
Really a silly question but this solution evades me.

Quote:

1 + 1 = 2
10 + 1 = 11
2 + 2 = 4
As you can see, double digits move the entire line one digit to the left, how can I correct this? I presume setw() is needed.
• 06-21-2004
swoopy
How do you want it to look?
Code:

``` 1 + 1 = 2 10 + 1 = 11  2 + 2 = 4```
Or?
Code:

``` 1 + 1 =  2 10 + 1 = 11  2 + 2 =  4```
• 06-21-2004
cyberCLoWn
Code:

``` 1 + 1 =  2 10 + 1 = 11  2 + 2 =  4```
:rolleyes:
• 06-21-2004
alphaoide
Is the problem with using setw() or the largest number of digit not known?
• 06-23-2004
cyberCLoWn
I can't get this sorted.

Code:

`cout << setw( 7 ) << num1 << "  -  " << num2 << setw( 5 ) << "=  ";`
The above gives me the following:

Code:

``` 4  -  3  =  x 14  -  14  =  x  6  -  2  =  x```
I make this change which still doesn't work:

Code:

`cout << right << setw( 7 ) << num1 << "  -  " << num2 << setw( 5 ) << "=  ";`
Code:

```10  +  11  =  x 6  +  1  =  x```
I'd like the subtraction and equal signs in a row in all cases with 1 to two digits but don't know how to get it like that. Help would be appreciated.

Code:

```10  +  10 =  x  9  +  1 =  x  1  +  11 =  x```
• 06-23-2004
Thantos
try
Code:

`cout<<setw(7)<<num1<<" - "<<setw(7)<<num2<<" = ";`
• 06-23-2004
cyberCLoWn
Got it.

Code:

`cout << right << setw( 7 ) << num1 << "  -" << setw( 3 ) << num2 << setw( 5 ) << "=  ";`
• 06-23-2004
Thantos
Code:

`<< setw( 5 ) << "=  ";`
Why? You are using a constent for setw's parameter on a fixed length string....
• 06-23-2004
cyberCLoWn
Dunno, but it works :D
• 06-23-2004
Thantos
so would
Code:

`<<"  = ";`
• 06-23-2004
cyberCLoWn
Guess I see what you mean. This was just a quick refresher project to get me back into the swing of C++. Have not really had a chance to touch it in a while.

Thanks anyhow Thantos