I'm not quite sure what's not working, but when I go to debug this program (I'm using Visual Studio Express for Windows) I get an error message that says "unable to start program."
Never seen this message before and not sure what I'm doing wrong.
Basically I'm trying to write course average and a gpa average to an external file so that the output looks something like this:
You also need to #include the <string> header file as well.
Also are you using the "using namespace std;" clause? If not then you must properly scope all of the std:: functions and classes.
Next look at this snippet:
1 2 3 4 5 6
string filename; // Is this line 19?
int i = 0;
for (int counter = 0; 1 < 3; ++i)
{
std::string filename;
Do you realize that you are creating two different variables named filename in two different scopes? And that that second variable will go out of scope when that for loop ends?
Thanks tallyman! That made the error go away and my program was able to compile, but something must still be wrong in the code because it keeps asking me to input the file name..
hmm, I am using the "using namespace std;" I didn't realize that I was creating two different variables for filename..
Should I get rid of the filename variable before the for loop? I think I need to reread a chapter of my book..
What I'm trying to do is be able to input three different external files with different sets of data and use a for loop for the iterations. I'm not supposed to hardwire the filename into the code.. I think that's why I want filename to go out of scoop when the for loop ends?
Should I get rid of the filename variable before the for loop? I think I need to reread a chapter of my book..
NO! Delete the variable definition inside your for loop. You use filename to open the file after the loop.
BTW, why are you using a loop to ask for a single file name multiple times? If you are trying to open multiple input files you need to create a string array.
BTW, why are you using a loop to ask for a single file name multiple times? If you are trying to open multiple input files you need to create a string array.
I'm trying to do it that way because that's how my professor wants us to code this.
The assignment says:
This program is to be executed on three separate sets of
external file input data. Each set resides in a unique file.
Use a counter controlled for() loop to take care of the three
iterations. Within the loop you’ll have to implement an
interactive path-filename input routine, in order to
open-trap-process-close these external files. DO NOT “hardwire”
the path-filename in your code. This must be done interactively
within the for() loop.