Output two dimensional array with width control - C++ Data Type

C++ examples for Data Type:Array

Description

Output two dimensional array with width control

Demo Code

#include <iostream>
using namespace std;
#include <iomanip>
void main()/*from  www  .j  av  a  2s.com*/
{
   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;
}

Result


Related Tutorials