Thread: Why aren't '1' of "col 1" and "1" aligned?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    254

    Why aren't '1' of "col 1" and "1" aligned?

    Hi

    I attached a screenshot from the output of the following code. Why aren't '1' of "col 1" and "1" (matrix entry) aligned? Could you please tell me the reason for this?

    Code:
    // read 3x4 matrix. print it, find the largest value,
    // count number of zeroes;
    
    #include <iostream>
    #include <cstdlib>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
    
    	const int R = 3;
    	const int C = 4;
    	float m[R][C];
    	float largest = 0;
    	float smallest = 10000;
    	int num_zeros = 0;
    	int r, c;
    	int entered_largest_r = 0, entered_largest_c = 0;
    	int entered_smallest_r = 0, entered_smallest_c = 0;
    
    	cout << "enter the matrix below\n\n";
    
    	for ( r=0; r<R; r++ )
    	{
    	        for ( c=0; c<C; c++ )
    	        {
    	                cout << "enter entry for row #" << (r+1)
    	                << " and column #" << (c+1) << ": ";
    	                cin >> m[r][c];
    
    	                if ( m[r][c] > largest)
    	                {
    	                     largest = m[r][c];
    	                     entered_largest_r = r+1;
    	                     entered_largest_c = c+1;
    	                }
    
    	                if ( m[r][c] < smallest )
    	                {
    	                        smallest = m[r][c];
    	                        entered_smallest_r = r+1;
    	                        entered_smallest_c = c+1;
    	                }
    
    	                if ( m[r][c] == 0)
    	                {
    	                        num_zeros = num_zeros++;
    	                }
    	        }
    
    	}
    
    	cout << "\n\n";
    
    	cout << "entered matrix is given below\n\n";
    	cout << setw(10) << "" << setw(10) << "col 1" << setw(10) << "col 2"
                 << setw(10) << "col 3" << setw(10) << "col 4\n\n";
    
    	for( r=0; r<R; r++ )
            {
    
                    cout << "\n" << setw(10) << "row " << (r+1);
    
    	        for( c=0; c<C; c++)
    	        {
    	                cout << setw(10) << m[r][c];
    
    	        }
    
    	}
    
    	cout << "\n\n\n";
    
    	cout << "largest matric element is: " << largest << ", entered at row #" << entered_largest_r
                 << " and column #" << entered_largest_c << "\n\n";
            cout << "smallest matrix element is: " << smallest << ", entered at row #" << entered_smallest_r
                 << " and column #" << entered_smallest_c << "\n\n";
            cout << "number of '0' matrix element(s): " << num_zeros << endl << endl;
    
    	system("pause");
    	return 0;
    
    }
    Attached Images Attached Images Why aren't '1' of &quot;col 1&quot; and &quot;1&quot; aligned?-iomanip2-jpg 
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-31-2009, 04:23 PM
  2. Replies: 46
    Last Post: 08-24-2007, 04:52 PM
  3. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  4. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM