#include <iostream>
#include <fstream>
using namespace std;


void namefile(ifstream & infile);
void openfile(ifstream & infile);
void displayScores(int scores);
void getData(ifstream & infile, int scores[], int & size);


int main()
{


}
void nameFile(ifstream & infile)
{
cout << "enter the file name";
cin >> infile;
}
void openfile(ifstream & infile)
{
ifstream infile;
infile.open (std::ifstream & infile);
}
void getData(ifstream & infile, int scores[], int & size)
{
int i = 0;
while (infile)
{
infile >> scores;
i++;


}
}
void displayScores(int scores)
{
cout << scores;
}

Recommended Answers

All 3 Replies

In future, post using code-tags, show what errors you're having, and give more detail to your problem.

Just to get some sort of idea on indentation, I've formatted the code for you.

#include <iostream>
#include <fstream>
using namespace std;

void namefile(ifstream & infile);
void openfile(ifstream & infile);
void displayScores(int scores);
void getData(ifstream & infile, int scores[], int & size);

int main()
{
}

void nameFile(ifstream & infile)
{
  cout << "enter the file name";
  cin >> infile;
}

void openfile(ifstream & infile)
{
  ifstream infile;
  infile.open (std::ifstream & infile);
}

void getData(ifstream & infile, int scores[], int & size)
{
  int i = 0;
  while (infile)
  {
    infile >> scores[i];
    i++;
  }
}

void displayScores(int scores)
{
  cout << scores[i];
}

Now, what are you trying to do here?

void nameFile(ifstream & infile)
{
  cout << "enter the file name";
  cin >> infile;
}

You're asking the user to enter a file name, and then... :icon_rolleyes:

I'm not going to put much effort into figuring out what each function and line does / is supposed to do. So if you want more help, post some detail on what each function is supposed to do, and what the program itself is ment to do.

What a crap this code is...........?
And you say you just want it to compile.!! Read your text book first.

What you need is a good book about C++ (and you also have to read it, otherwise it won't be a good practice).

Please check the following thread about C++ books: http://www.daniweb.com/forums/thread70096.html

I personally can recommend the "C++ Black Book", one of the best C++ books ever written, if you can get your hands on a copy of it ...

I tried to interpret what exactly you were trying to do and I came up with the following code:

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

string getFileName(void);
void dispData(string filename);

int main(void)
{
    string filename; // create variable to hold the filename

    filename = getFileName(); // get the filename from the user

    dispData(filename);

    cin.get();
    return 0; // tell the operating system that everything went well
}

string getFileName(void)
{
    /* Get the filename from the user */

    string filename; // create variable to hold the filename

    cout << "Enter the file name: ";

    getline(cin, filename); // store the filename

    cout << endl; // send a newline to the screen

    return filename; // return the filename
}

void dispData(string filename)
{
    /* Get the data from the file and display it on the screen */
    /* Caution: Please make sure that there are only numbers in the file !!! */
    /*          Otherwise the program will do strange! */

    ifstream file; // create an ifstream object

    file.open(filename.c_str()); // open the file for input

    if(!file.is_open())
    {
        // there was an error while opening the file
        cerr << "ERROR: Could not open the file \"" << filename << "\" !" << endl; // display an error message
        exit(1); // exit the program
    } else {
        int score;
        while (!file.eof()) // repeat the loop until the whole file has been read...
        {
            file >> score;
            cout << score << endl; // print the score on the screen
        }

        file.close(); // close the file
    }
}

Yet to mention: you just made too much errors in your posted code, so I'm not describing what exactly you did wrong, it would take ages...

Hope this helps!

P.S.: Sorry if my English is bad, my native language is Dutch...
(Remember that I'm only trying to help)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.