### c++ 1D Arrays, reading a txt file

Okay, I'm totally new to arrays, and my professor is restricting that we only use 1d arrays and not 2d.

I need to write a program that reads a txt file of quiz grades. Where the first column is the quiz number, and the second column is the possible points, and the 3rd column is points scored. And the last row is extra credit points. example of the txt file.

6 // number of quizes
0 27 14.5
1 14 11
2 30 24
3 34 31
4 9 7.5
5 14 10
3 // free points

With the txt file, I need to display the txt file, and ask the user to drop a certain quiz, and then it should output the quiz average.

Also, it needs the option of repeating the drop quiz/average part, and to where if the user inputs a negative number, it ends the program.

I have no idea how to start this.... Please, if anyone can help that would be super amazing.
 Please, if anyone can help that would be super amazing.

It would be super amazing if you start writing the code and ask some specific questions when you feel stuck somewhere. No need to hope anyone will do it instead of you :)

You can use 1D array instead of 2D array for example in that way:
 123456 int a2d[][]; int a1d[] int x, y; a2d[y][x] = ... a1d[y * 3 + x] = ...

Last edited on
Hullo, dkmike.

You will need to use an ifstream to load the file.
Take a look at this:
http://www.cplusplus.com/doc/tutorial/files/

Do you know how to use arrays well?

So, first, open the file. Then, input the first number and make an array like this:

int array[FIRST_NUMBER_READ * 3 + 1]; //One for each number

Then read the numbers in order with the << operator into the array slots. When you have done that, then avg them.
Topic archived. No new replies allowed.