[Solved] Extra space appearing out of nowhere (Please Look) [closed]


The issue is in lines 36 and 39.

In this case, std::setw and std::setprecision only operate on the next number. In other words

std::cout << std::setw(3) << 10 << std::endl;
std::cout << 10;

Will output

 10
10

There isn’t an extra space in front of the first. Rather, the second is lacking a space.

Redefine your print function:

void printArray( double array[], int numberOfValues, int numberPerLine, int spaces, int digits );

Call it like this:

printArray( array, numberOfValues, numberPerLine, spaces, digits );

And add the setw and setprecision lines to the appropriate cout statements:

for (i = 1; i <= numberOfValues; i++) {
    if ( i % numberPerLine == 0 ) {
        cout << setw(spaces) << setprecision(digits) << array[i-1] << endl;
    } else {
        cout << setw(spaces) << setprecision(digits) << array[i-1] << "\t";
    }
}

Everything will be spaced right. Note that this still doesn’t fix the lack of std::fixed. You won’t be showing the number of digits requested by the second input.

0

solved Extra space appearing out of nowhere (Please Look) [closed]