Hello boypetey17,
Your use of "left " is not working the way you are thinking. "std::left" or "std::right is followed by "std::setw(5)". The number in ()s sets the size of space for what follows. If you use "std::left" or "std::right" this tells the output to position what is output to the ""left " or "right" of the space set by "std::setw()".
So in your code replace the "left at the beginning of the line with "std::setw()" and the "left " at the end of the line just delete it.
The line
std::cout << std::fixed << std::showpoint << std::setprecision(2);
only needs to be done once, so put it above the for loop. You do not have to do it every time in the for loop. Once you set "std::fixed", "std::showpoint" and "std::setprecision(2)" these will not change until you tell the program something different.
When I changed the for loop this way:
1 2 3 4 5 6 7 8 9 10
|
std::cout << std::fixed << std::showpoint << std::setprecision(2);
for (size_t i = 0; i < SIZE; i++)
{
Point myPointer = randomIntforXorY(engine);
myPointer = Point(randomIntforXorY(engine), randomIntforXorY(engine));
cout << std::setw(4) << "x: " << std::setw(4) << myPointer.getX();
cout << std::setw(4) << " y: " << std::setw(4) << myPointer.getY();
cout << std::setw(25) << " Distance from Origin: " << std::setw(6) << myPointer.distanceFromOrigin() << endl;
}
|
It gave me the output of:
x: 13 y: -1 Distance from Origin: 13.04
x: -9 y: -9 Distance from Origin: 12.73
x: 0 y: -11 Distance from Origin: 11.00
x: -9 y: 3 Distance from Origin: 9.49
x: 6 y: -10 Distance from Origin: 11.66
x: -3 y: -5 Distance from Origin: 5.83
x: 6 y: 12 Distance from Origin: 13.42
x: -13 y: -2 Distance from Origin: 13.15
x: 7 y: 7 Distance from Origin: 9.90
x: 3 y: -10 Distance from Origin: 10.44
x: 4 y: 6 Distance from Origin: 7.21
x: -14 y: -11 Distance from Origin: 17.80
x: -10 y: -13 Distance from Origin: 16.40
x: 3 y: 6 Distance from Origin: 6.71
x: -10 y: -7 Distance from Origin: 12.21
Press Enter to continue
|
Which I think is what you are looking for. When working correctly strings are positioned left and numbers are positioned right with the idea that decimal points will line up.
One last thought: the "std::setw()" needs to be wide enough to account for maximum number of characters that will be printed. Anything shorter will be padded with spaces. You can also make the width one more than you need to adjust spacing. And do not forget to account for the minus siine on negative numbers.
Hope that helps,
Andy