Hello, I'm still pretty new to C++. I'm wondering if anyone can guide me in the right direction? For homework, I'm supposed to infile the following from this text file into an array:
9th
10th
11th
12th
F
C
B
A
Math
21
15
32
14
5
8
41
22
9
11
32
21
4
25
21
4
Science
17
5
10
16
25
14
19
24
26
7
15
13
14
16
5
5
English
7
12
15
16
22
21
16
9
9
14
16
12
12
18
8
34
The output should look similar to this (The x's should be the numbers):
MATH: F C B A
9th x x x x
10th x x x x
11th x x x x
12th x x x x
SCIENCE: F C B A
9th x x x x
10th x x x x
11th x x x x
12th x x x x
ENGLISH: F C B A
9th x x x x
10th x x x x
11th x x x x
12th x x x x
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main()
{
ifstream inFile;
inFile.open("Test_Scores.txt");
string year[4]; //there are 4 years 9th - 12th
char letter[4]; // there are 4 letters, A-F
string subject[3]; //only 1 subject
int grades[3][4][4]; // there are 48 grades
for(int z=0; z<3; z++)
{
inFile>>subject[z]; // since there is only 1 subject.
for (int x=0; x<4; x++) // getting the 4 letters.
{
inFile>>letter[x];
}
for (int x=0; x<4; x++) //the next 4 lines look the same
{
inFile>>year[x]; //it starts with a year
for (int y=0; y<4; y++)
{
inFile>>grades[z][x][y]; // and gets 4 grades for that row
}
}
}
////////////////////////////////////////////////////// Display
for(int z=0; z<3; z++)
{
cout<<subject[z];
for (int x=0; x<4; x++)
{
cout<<letter[x];
}
for (int x=0; x<4; x++)
{
cout<<year[x];
for (int y=0; y<4; y++)
{
cout<<grades[z][x][y];
}
}
}
return 0;
}
Pretty simple, I know, but I just can't seem to figure it out. I've been working on this for about five hours trying different approaches but keep getting weird numbers when I run it like "-858993460" or symbols "||}". Can someone explain what I'm doing wrong? I know it's something so simple that I'm oblivious to.