Hi guys
I am working on some homework at the moment but im not stuck on a logial problem. The program is working absolutly fine and the output is just what is required.
My issue comes with the spacing of the output. I am using a 2 dimensional array and the columns are not lined up with the headers. I am using setw() to ensure I get good spacing of each column in the output but they keep going off balance dispite various attempts to change the value of setw().
I have heard of std::left and was wondering if this could help my spacing issues on this occasion. Here is my code, this is uncompleted so excuse the lack of comments.
Code:#include <iostream> #include <iomanip> // main function - driver ////////////////////////////////////////////////////// // int main ( void ) { const int SALES_PERSON = 4; // rows const int SALES_ITEMS = 5; // columns int salesNumber = 1; int sales[ SALES_PERSON ][ SALES_ITEMS ] = {{ 0, 0 }}; for ( int i = 0; i < SALES_PERSON; ) { for ( int j = 0; j < SALES_ITEMS; j++ ) { std::cout << "Enter sales total for item " << j << " for salesman number " << i << " : "; std::cin >> sales[ i ][ j ]; } i++; } // table headers std::cout << "\n\nSalesman" << std::setw( 12 ) << "Prod 1" << std::setw( 12 ) << "Prod 2" << std::setw( 12 ) << "Prod 3" << std::setw( 12 ) << "Prod 4" << std::setw( 12 ) << "Prod 5" << "\n\n"; for ( int i = 0; i < SALES_PERSON; i++ ) { for ( int j = 0; j < SALES_ITEMS; j++ ) std::cout << salesNumber << std::setw( 14 ) << sales[ i ][ j ]; std::cout << std::endl; salesNumber++; } std::cin.get(); // freeze console output window std::cin.ignore(); return 0; // return value from int main }



LinkBack URL
About LinkBacks


