Hello everyone, I am having trouble with an assignment where I have to read in letter grades from a file and then display them on screen.
My thought process was to use two for loops in order to cycle through the file and then display it but all I am getting so far is this: ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠
All the text file has is this:
A
A
B
C
C
F
C
D
B
B
A
C
B
A
B
I would really appreciate it if anyone can give me a hint about what I'm doing wrong. Thank you for your time.
You may want to review your documentation on arrays. And it might be easier if you start with a statically allocated and populated array, to get your print function working correctly.
Something like:
1 2 3 4 5 6 7
int main()
{
int array[3][4] = { {1,2,3,4}, {5,6,7,8}, {9,10,11,12}};
// Now print out the above array to the console (cout).
...
If I've understood you correctly, this is easier than you think. You can replace 15 by the number of grades you want (that is, the number of grades in your grades file).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <fstream>
usingnamespace std;
int main ()
{
ifstream in ("grades.txt");
char grade;
for (int i=0;i<15;i++)
{
in >> grade; // grade equals each one of the grades, but only one at a time.
cout << grade << endl; // this line displays each grade
}
}