Formatting tables in c++

Viewed 42

I'm trying to print out values in a neat column, but none of the formatting I've used has worked. I've tried setw(), left and right align, \t.

I want neat rows, but as the values get larger the rows are skewing. This is the output I'm trying to fix. I also can't figure out how to get the numbers lined up with a right orientation instead of a left.

    Balance and Interest With Additional Deposits

============================================================= Year Year End Balance Year End Earned Interest

    1               $150.62                 $0.62
    2               $201.46                 $0.84
    3               $252.51                 $1.05
    4               $303.77                 $1.26
    5               $355.24                 $1.47
    6               $406.93                 $1.69
    7               $458.84                 $1.90
    8               $510.96                 $2.12
    9               $563.29                 $2.34
    10              $615.85                 $2.56
    11              $668.62                 $2.77
    12              $721.62                 $2.99
    13              $774.83                 $3.22
    14              $828.27                 $3.44
    15              $881.93                 $3.66
    16              $935.81                 $3.88
    17              $989.92                 $4.11
    18              $1044.25                        $4.33
    19              $1098.81                        $4.56
    20              $1153.60                        $4.79

for (i = 1; i <= m_numYears; ++i) {
    m_newBalance = m_openingAmount + m_monthlyDeposit;
    m_yearEndInterest = m_newBalance * ((m_apr / 100) / 12);
    m_yearEndBalance = m_newBalance + m_yearEndInterest;
    cout << "\t" << i << "\t\t" << fixed << setprecision(2) << "$" << m_yearEndBalance << 
    "\t\t\t" << "$" << m_yearEndInterest << endl;
0 Answers
Related