Help with setting up the program

Write your question here.
I currently working on a code that takes info from files and put it into a string and int classes 2d array. I get the E0349 error when I try to run it, I might just be overthinking it but I'm not sure.

here's 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
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>

using namespace std;
//
struct int_string
{
	int num;
	string heads;
};

int main()
{
	int_string chart1[13][6];
	int m = 0;


	ifstream visitFile("Visitors.txt");
	ifstream monthFile("Months.txt");
	// 1 display the chart
	{
	
		visitFile.open;
		monthFile.open;

		while (m < 13 && monthFile >> chart1[13][6])
			m++;

		for (int r = 1; r < 13; r++)
			for (int c = 1; c < 6; c++)
				visitFile >> chart1[r][c];

		for (int x = 0; x < 13; x++)
			for (int y = 0; y < 6; y++)
				cout << chart1[x][y];



	}
}


I feel like it would be better if I include the instructions I'm supposed to follow.
Write a C++ program to calculate to analyze the data from the number of visitors to Sleeping Bear Dunes in Michigan in 2015.
Requirements
1. Read the data from the Months.txt and Visitors.txt files. The text files are provided for you to download. The data was obtained from the National Park Service website.
2. Design the program so the user enters a menu item and the following is displayed
a. Display the chart below
b. Totals and display all visitors to the dunes.
c. Total and display each month (add across the rows (except the Total Overnight Stays).
d. Display the percentage of Total Overnight Stays compared to total visits. (Total Overnight Stays/(Recreation Visitors + Total Overnight Stays)
3. Design the program so the user can continuously enter a menu item and terminate the program when done.
Last edited on
closed account (E0p9LyTq)
Line 28, chart1[13][6] is out of bounds. You are trying to access the 14th row, 7th column.

And what exactly is the error you are receiving. The entire error, not just the error code.
I'm sorry I still don't understand this is the first time I'm experimenting with arrays, but i found that if i dont use the struct class for my 2d array the errors go away but then i get an output that looks like this.

-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460-858993460Press any key to continue . . .
What exactly is in your two text files?

Given your structure, and if months.txt is just a list of integers, then perhaps:
1
2
3
4
    int_string chart1[13];

    while (m < 13 && monthFile >> chart1[m].num)
        m++;


If your visitor file contains 6 strings per month, then perhaps these ideas:
1
2
3
4
5
6
7
8
9
struct int_string
{
	int num;
	string heads[6];
};

    for (int r = 0; r < 13; r++)
        for (int c = 0; c < 6; c++)
            visitFile >> chart1[r].heads[c];

in the month's file is
January February March April May June July August September October November December
and in the visitor file, it is
6340 27 34 6 67
12191 7 7 2 16
11548 14 24 10 47
36053 323 231 27 581
74361 2764 1890 1101 5755
256462 4879 1363 2727 8970
483291 13797 8823 7038 29658
358885 13100 10346 7816 3162
141297 8945 10492 2290 21728
119175 3193 6164 281 9638
22377 337 629 22 988
13653 24 20 7 51


its supposed to have an output of

row 1)months recreation visitors tent campers RV camper backcountry campers Total overnight stays
row 2)January 6340 27 34 6 67
row 3)February 12191 7 7 2 16
row 4)March 11548 14 24 10 47
row 5)April 36053 323 231 27 581
row 6)May 74361 2764 1890 1101 5755
row 7)June 256462 4879 1363 2727 8970
row 8)July 483291 13797 8823 7038 29658
row 9)August 358885 13100 10346 7816 3162
row 10)September 141297 8945 10492 2290 21728
row 11)October 119175 3193 6164 281 9638
row 12)November 22377 337 629 22 988
row 13)December 13653 24 20 7 51
Topic archived. No new replies allowed.