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"); } }
cout << setw(3) << temp[c];
by default, uses spaces fill, looks want.
you need include iomanip documentation says.
Comments
Post a Comment