need help with reading from files

Good evening forum!
I need help with my lab homework. I'm pretty basic with C++ and cant figure out the problem.

My HW assignment is as follows:

I have some info, I need to implement it into code and do certain instructions.
The assignment looks like this:



_________________________________________________________________________________

Background:
The local pet store has 35 different bowls with fish in them arranged in a circle in the “fish room.” The first six have goldfish, the next seven have guppies, the next nine have angel fish, the next eight have goldfish, and the last five hold tiger fish. As the bowls vary in size, the number of fish that are in each bowl at the start of the day also varies. The count of fish in each bowl is as follows:
Bowls 1 – 3: 15 fish
Bowls 4 – 7: 8 fish
Bowl 8: 19 fish
Bowls 9 – 12: 16 fish
Bowls 13 – 22: 14 fish
Bowls 23 – 24: 31 fish
Bowls 25 – 29: 9 fish
Bowls 30 – 33: 26 fish
Bowls 34 – 35: 8 fish
Houston…We have a Problem:
A trained seal finds its way into the store. The seal begins to eat fish in the following manner.
a. It walks over to bowl #1.
b. It counts four bowls and then eats a fish (the first fish it eats comes from bowl #4 and it’s a goldfish).
c. It again counts four, starting with the next available bowl, and eats a fish (the second fish it eats comes from bowl #8 and it’s a guppy.
Method:
The conditions that controls the seal are: a. If there are no fish left in a bowl, the seal does not count the bowl and skips it and goes to the next bowl containing fish. (It starts counting four from the bowl it ate from.)
b. The bowls are arranged in a circle, there is no last bowl.
c. After the seal eats a bowl #35, it counts over 4 bowls and finds itself at bowl #4. (Bowl #3 if four bowls away from 34, etc.)
d. The seal continues to eat until 361 fish are consumed.
Your Task:
You are to write a C++ program that will calculate and report the following (put breaks in so the user can read):
a. The number and type of fish in each bowl before the seal begins eating.
b. The total number of each type of fish before the seal begins to eat.
c. The number and type of fish left in each bowl after each time the seal eats.
d. The total number of each type of fish remaining after the seal eats.
_______________________________________________________________________________



My idea was to write down a file and read the info from a file. My file input looks like this:

15
goldfish
15
goldfish
15
goldfish
8
goldfish
8
goldfish
8
goldfish
8
guppy
19
guppy
16
guppy
16
guppy
16
guppy
16
guppy
14
guppy
14
angel
14
angel
14
angel
14
angel
14
angel
14
angel
14
angel
14
angel
14
angel
31
goldfish
31
goldfish
9
goldfish
9
goldfish
9
goldfish
9
goldfish
9
goldfish
26
goldfish
26
tiger
26
tiger
26
tiger
8
tiger
8
tiger


and I'm trying to create 2 arrays, one for the bowls, and another for the fish type to count it later. my program gets an error message "Stack failure" for the bowls[] array after i run the program to check. I need help with reading the info from the file.
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
 #include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	ifstream myfile;
	myfile.open("fishes.txt");
	
	if (myfile.fail())
	{
		cout << "Error while opening file." << endl;
		exit(0); 
	}

	int bowls[34];
	string fish[34];

	int i = 0;

	while(!myfile.eof())
	{
		myfile >> bowls[i] >> fish[i];
		i++;
	}

	for (int i = 0; i < 35; i++)
	{
		cout << "Bowl Number " << i << ": " << bowls[i]<< " " << fish[i] << endl;
	}


	system("pause");
	return 0;


}


Thank you for reading this.
closed account (2UD8vCM9)
Your arrays are of size 34. They need to be size 35.
Your arrays are of size 34. They need to be size 35.


Wow, with all honesty, I didn't notice that. I was breaking my head over this. Thank you so much
Topic archived. No new replies allowed.