i made a post similar to this but have updated my code and it is working much more functionally. so the idea is to read from the data7.txt file, store the info into the arrays in the buildArrays function, and display them in the printArrays function. there's more to it but i'll get there when i get there. right now, i can sucessfully display the first row of numbers from the data file, but that's it, it's stopping there. i'm unsure of how to get the program to keep displaying all the info until everything is displayed. i'm using "i" so that ideally the array will start at i=0, then go to 1=1, 1=2, etc, until it's run through all the data. i hope that makes sense. here is what i have so far. the sortArrays function is there but I haven't gotten into working on that yet, so it's just there, not doing anything at the moment, so ignore that. (unless you want to help, heh) thanks.
Code:
#include <iomanip>
#include <iostream>
#include <fstream>
#include <ctype.h>
using namespace std;
const int LENGTH = 30;
int family[LENGTH];
int item[LENGTH];
int quantity[LENGTH];
double price[LENGTH];
int buildArrays (int family[], int item[], int quantity[], double price[])
{
double num;
ifstream inFile;
inFile.open( "data7.txt" );
if( inFile.fail() )
{
cout << "text failed to open";
exit( -1 );
};
int i=0;
while (inFile)
{
inFile>>num;
family[i]=num;
inFile>>num;
item[i]=num;
inFile>>num;
quantity[i]=num;
inFile>>num;
price[i]=num;
i++;
}
return (i);
}
void printArrays (int family[], int item[], int quantity [], double price[])
{
int i=0;
cout<<family[i]<<"\n"<<item[i]<<"\n"<<quantity[i]<<"\n"<<price[i];
i++;
}
void sortArrays (int family [], int item[], int quantity [], double price[])
{
}
int main()
{
buildArrays(family, item, quantity, price);
printArrays(family, item, quantity, price);
return 0;
}