Error output -858993460

I need to be able to read the txt file and put it in an array. I need to do this because the end result needs to look like this:


Month                    Rec             Tent           RV           Back       T Overnight
                      Visitors          Campers       Campers       country      Stays
January                   6340	             27	           34	          6	   67
Feburary                 12191	              7	            7	          2        16
March                    11548	             14	           24	         10	   47
April                    36053	            323	          231	         27	  581
May                      74361	           2764	         1890	       1101	 5755
June                    256462	           4879	         1363	       2727	 8970
July                    483291	          13797	         8823	       7038	29658
August                  358885	          13100	        10346	       7816      3162
September               141297	           8945	        10492	       2290     21728
October                 119175	           3193	         6164	        281      9638
November                 22377	            337	          629	         22       988
December                 13653	             24	           20	          7        51


here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "pch.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;
int main()
{
	
// creating the display file

// creating the arrays ROWS ARE ALWAYS FIRST "[]"[] 
	const int month_column = 5;
	const int 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;
}
Last edited on
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
I figured it out for those who were curious I was using the wrong loop to print the function. Instead of the
1
2
3
4
5
6
7
8
for (int row = 0; row < month_row; row++)
	{
		for (int col = 0; col < month_column; col++)
		{
			cout << Jan[countr][countc] << " ";
		}
		cout << endl;
	}


it needs to be this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
for (int row = 0; row < month_row; row++)
	{
		for (int col = 0; col < month_column; col++)
		{
			Visitors >> ppl[row][col];
		}
	}
	
	for (int row = 0; row < month_row; row++)
	{
		for (int col = 0; col < month_column; col++)
		{
			cout << right << setw(10) << ppl[row][col] << " ";
		}
		cout << endl;
	}
Last edited on
Topic archived. No new replies allowed.