#include "pch.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
usingnamespace std;
int main()
{
// creating the display file
// creating the arrays ROWS ARE ALWAYS FIRST "[]"[]
constint month_column = 5;
constint month_row = 12; // array element size 60 (12 rows x 6 columns)
int Jan[month_row][month_column]; //january array - has 5 elements
int countc = 0;
int countr = 0;
int count = 0;
int Jtotal = 0;
ifstream Visitors;
//cout << left << setw(10) << Months << setw(10) << right << Visitors << endl;
Visitors.open("Visitors.txt");
while (countc < month_column && Visitors >> Jan[countr][countc])
countc++;
Visitors.close();
// test if the array reads what I want it to for the month given
// months that read properly are: January
cout << "The numbers are: ";
for (int row = 0; row < month_row; row++)
{
for (int col = 0; col < month_column; col++)
{
cout << Jan[countr][countc] << " ";
}
cout << endl;
}
// test for adding up a month's contents
// successfull additions: January
for (countc = 0; countc < 4; countc++)
Jtotal += Jan[countr][countc];
cout << "January's total number of visitors are: " << Jtotal << endl;
return 0;
}
my output needs to be straight across but I couldn't get it to properly line up. Each column needs to be aligned so that the one's place is aligned. I will work on fixing it still but I quickly fixed it enough so you can get the idea.
If you want your columns to line up, you need to format your output so that the number of digits in the displayed value, and the number of spaces preceding it, sum to a constant. A good first step would be to write a routine to calculate the number of digits in an answer.
That is something I will definitely need later but I meant when I was putting the output here for you guys to see when I was talking about that. The Former is much more confusing to me right now