The instructions state I must use a 1 dimensional array to read the 1st column of data from a text file.
Then i must use a 2-dimensional array to read the number associated with the names.
Both arrays must be parallel array.
The user must be able to input the Term number, so they can retrieve the number associated with that user. I'm not concerned about this part for now.
My main goal right now, is for the compiler to generate the contents of the text file.
This is what the Data.txt file looks like
adam 21 34
bram 56 23
cole 21 38
dave 15 13
|
The program will first begin by displaying all that content in the following format:
Name: adam Result 1: 21 Result 2: 34
Name: bram Result 1: 56 Result 2: 23
Name: cole Result 1: 21 Result 2: 38
Name: dave Result 1: 15 Result 2: 13
I did the following 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
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string name[4]; //generate 4 names from file.
double results[4][3]; //result of each name's session, 4rows 3columns
int row; //row counter
ifstream inFile;
inFile.open("Data.txt");
cout << "The file's data: " << endl;
for (row = 0; row < 4; row++){ //read the array of Names
inFile >> name[row]; }
inFile.close();
for (row = 0; row < 4; row++){ //display the array
cout << "Name: " << name[row] << endl; //I'll worry about the results later << " Result 1: " << results[rR][1] << endl;
}
system ("pause");
return 0;
|
And the program outputs
Name: adam
Name: 21
Name: 34
Name: bram
Also please, keep in mind, that i'm taking things one step at a time. If i delete the numbers from the text file, all the Name's are able to display properly..
Thanks in advanced.