C++ Array Output two dimensional array with width control
#include <iostream> using namespace std; #include <iomanip.h> void main()/*from ww w .j a v a 2 s. c om*/ { float disks[2][4]; // Table of disk prices. int row, col; disks[0][0] = 2.39; // Row 1, column 1 disks[0][1] = 2.75; // Row 1, column 2 disks[0][2] = 3.29; // Row 1, column 3 disks[0][3] = 3.59; // Row 1, column 4 disks[1][0] = 1.75; // Row 2, column 1 disks[1][1] = 2.19; // Row 2, column 2 disks[1][2] = 2.69; // Row 2, column 3 disks[1][3] = 2.95; // Row 2, column 4 // Print the prices for (row=0; row<2; row++) { for (col=0; col<4; col++) { cout << "$" << setprecision(2) << disks[row][col] << "\t"; } cout << "\n"; // Prints a new line after each row. } return; }