[Homework help] Stuck at getData

my English is not that great

so the teacher ask to not store the input and i do not know how because either way it would do and mess up the rest of the file..so i'm still stuck at getData. this is what i have so far.
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  #include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

const int MAX_UNI = 1000;

void getData(string uniName[MAX_UNI], string state[MAX_UNI], string city[MAX_UNI],
             int tuition[MAX_UNI], int enrollment[MAX_UNI],
             double aveFreshRetention[MAX_UNI], double percentOfStudent[MAX_UNI]);
int sortArray();

int main()
{
    string uniName[MAX_UNI];
    string state[MAX_UNI];
    string city[MAX_UNI];
    int tuition[MAX_UNI];
    int enrollment[MAX_UNI];
    double aveFreshRetention[MAX_UNI];
    double percentOfStudent[MAX_UNI];

    getData(uniName, state, city, tuition, enrollment, aveFreshRetention, percentOfStudent);

    return 0;
}

void getData(string uniName[MAX_UNI], string state[MAX_UNI], string city[MAX_UNI],
             int tuition[MAX_UNI], int enrollment[MAX_UNI],
             double aveFreshRetention[MAX_UNI], double percentOfStudent[MAX_UNI])
{
    char rand;
    ifstream infile;
    infile.open("universities.txt");

    if(infile.fail())
    {
        cout << "File is corrupted\n";
    }

    infile >> rand;
    for(int i = 0; i < MAX_UNI; i++)
    {
        infile.ignore();
        getline(infile, uniName[i]);
        infile >> state[i];
        infile.ignore();
        getline(infile, city[i]);
        infile >> tuition[i];
        infile >> enrollment[i];
        infile >> aveFreshRetention[i];
        infile >> percentOfStudent[i];

    }

    cout << rand << endl;
    for(int i = 0; i < 2; i++)
    {
        cout << "University: " << uniName[i] << endl;
        cout << "State: " << state[i] << " \n";
        cout << "City: " << city[i] << endl;
        cout << "Tuition: " << tuition[i] << " \n";
        cout << "Enrollment: " << enrollment[i] << " \n";
        cout << "Average Freshman Retention: " << aveFreshRetention[i] << endl;
        cout << "Percentage of Student Graduated: " << percentOfStudent[i] << endl << endl;
    }
}
Last edited on
Read one entry, output data on screen, read next one, etc.

for example it can be like that:

1
2
3
4
5
6
7
8
9
while(infile) {

    //<read stuff in single variables>

    if(!infile) //Break if read failed (no more entries in file)
        break;
    
    //<Output stuff>
}
thats what i did. When i input it in, it got the first college but not the second one because you have to discard the percent of acceptance. which is the last number. Or else it eill jump into the next one and messed it up
you have to discard the percent of acceptance
Could youelaborate? From what I see it is just a value in file unique for each university.
her are the instructions.

Purpose: Analyze and summarize the data collected on United States universities.
In this program you will write a C++ program to analyze a small subset of the data that has been collected. Using universities.txt for data

THEME ISSUES: one-dimensional arrays, if statements, file input, file output, searching, sorting
Absolutely no two-dimensional arrays, no structures and no menu function.
Topic archived. No new replies allowed.