array file input

Im having trouble outputting my array file, im using a separate function instead of having it in the main function,is there anything that im doing wrong??

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

void displayFile(int);

int main()
{

cout << " Charge Account Validation created by Cedric Shumate"<< endl;

cout << "Enter a number in the account or 9999 to quit: ";
int number;
cin >> number;
while (number < 1 || number >9999)
{
cout << "Error: Enter a number that is in the account: ";
cin >> number;
}


return 0;
}

void arrFile()
{
const int ACCOUNT_SIZE = 10;
int account[ACCOUNT_SIZE];
int count = 0;

ifstream inputArrayfile;

inputArrayfile.open("charges.txt");

while (count < ACCOUNT_SIZE && inputArrayfile >> account[count])
count++;

inputArrayfile.close();

}



where did u cal ur function arrFile() in main ??

I don't know what is supposed to be the output here?

Function main() simply requests an integer from 1 to 9999.
Then the program ends.


You declare a function, void displayFile(int); but the body of the function has not been defined. In any case this function is never called.

You've also defined a function void arrFile()which is never called.
If it was called, it would try to read some values (input) from a file, into the local array int account[ACCOUNT_SIZE];, though that array goes out of scope when the function ends, so it's not particularly useful as it stands.

Overall, this looks like a work in progress. There may be mistakes in the code, but the biggest problem is that it is simply incomplete.

Function main() needs to do more, such as calling one or both of your functions for example.
Last edited on
ok calling the function in main is where im having the problem
i use arrFile() in main but its telling me there is an error
error C2660 function does not take 1 arguements
what is the problem here??
post ur code bro
and as the error tells that your function have problem with the arguements that you passing
Here is the code

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

void arrFile();
void displayFile(int);
void sortFile(const int [], int);
void displaySortfile(const int [], int);
int searchFile(const int [], int, int);


int main()
{

cout << " Charge Account Validation created by Cedric Shumate"<< endl;

arrFile();

cout << "Enter a number in the account or 9999 to quit: ";
int number;
cin >> number;
while (number < 1 || number >9999)
{
cout << "Error: Enter a number that is in the account: ";
cin >> number;
}


return 0;
}


void arrFile()
{
const int ACCOUNT_SIZE = 10;
int account[ACCOUNT_SIZE];
int count = 0;

ifstream inputArrayfile;

inputArrayfile.open("charges.txt");

while (count < ACCOUNT_SIZE && inputArrayfile >> account[count])
count++;

inputArrayfile.close();

}



void displayFile(const int array[], int account)
{
cout << "Original Order";
for (int count = 0; count < account; count++)
cout << array[count] << " ";
cout << endl;

}
you are still calling none of your function in the main program
that is the biggest error of you code
so would i put
arrFile();
and
displayFile();
in the main??
also im having trouble with the arguments while calling the function
you also need to define prototype for these functions
or u can add the functions before main()
like
void arrFile()
then your main
but i already defined the prototypes??


void arrFile();
void displayFile(int);
Topic archived. No new replies allowed.