Formatting columns in C++ -


i have following program generates multiplication table. formatting problem arises when outputs reach double digits. how straighten out columns?

#include <iostream>  using namespace std ; int main()  {   while (1 != 2)   {     int column, row, c, r, co, ro;       cout << endl ;      cout << "enter number of columns: " ;     cin >> column ;     cout << endl ;     cout << "enter number of rows:    " ;     cin >> row ;     cout << endl ;      int temp[column] ;     c = 1 ;      r = 1 ;      for(ro = 1; ro < row ; ro ++ ){       for(co = 1; co < column ; co ++ ){             c = c ++ ;             r = r ++ ;             temp [c]= co * ro;              cout << temp[c] << " ";       }       cout << endl ;     }     system("pause");     } } 

use setw output manipulator:

cout << setw(3) << temp[c];

by default, uses spaces fill, looks want.

you need include iomanip documentation says.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -