# Thread: Dumb alignment

1. ## Dumb alignment

Really a silly question but this solution evades me.

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.

2. 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```

3. Code:
``` 1 + 1 =  2
10 + 1 = 11
2 + 2 =  4```

4. link to setw()
Is the problem with using setw() or the largest number of digit not known?

5. 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```

6. try
Code:
`cout<<setw(7)<<num1<<" - "<<setw(7)<<num2<<" = ";`

7. Got it.

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

8. Code:
`<< setw( 5 ) << "=  ";`
Why? You are using a constent for setw's parameter on a fixed length string....

9. Dunno, but it works

10. so would
Code:
`<<"   = ";`

11. 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

Popular pages Recent additions