10 E:\Lab 7 - Test Averages\Lab7.cpp variable or field `calcavg' declared void
10 E:\Lab 7 - Test Averages\Lab7.cpp `ifstream' was not declared in this scope
10 E:\Lab 7 - Test Averages\Lab7.cpp `ifstream' was not declared in this scope
10 E:\Lab 7 - Test Averages\Lab7.cpp `string' was not declared in this scope
10 E:\Lab 7 - Test Averages\Lab7.cpp `name' was not declared in this scope
10 E:\Lab 7 - Test Averages\Lab7.cpp expected primary-expression before "float"
^I get this error 6 times, total. All line 10.
10 E:\Lab 7 - Test Averages\Lab7.cpp initializer expression list treated as compound expression
E:\Lab 7 - Test Averages\Lab7.cpp In function `int main(int, char**)':
26 E:\Lab 7 - Test Averages\Lab7.cpp `calcavg' cannot be used as a function
So, there's something wrong with what I coded in line 10, but I don't see the problem...
FIRST, put code in [ code] .... [ /code] blocks (without the spaces after the "["). This makes it readable for us!
The first issue is the namespace std. This is a case of a compiler not giving a very helpful error. I see the same thing on gcc, which is what I'm assuming you're using too. It's not because the function is declared void type, it's because it doesn't know what ifstream and string are.
When you use something like ifstream or string, you either have to include: usingnamespace std;
... Or you have to use std::ifstream, or std::string everytime.
That gets rid of most of the errors.
That leaves one error. I've got to run out really quick. If no one else responds, I'll come back to this, but I bet someone will beat me to it.
Ahh, I see that your original example did have the line "using namespace std;", just below where I was expecting it. Being in a hurry earlier, missed that it was there since it wasn't after the defines. The namespace won't be used without being specified before that line exists, so moving it up as you have is the correct way to go.
As for the new error... When you see a linker error of an undefined reference, that's when it knows there needs to be code linked in that it hasn't found. In this case, the program forward declares a prototype of calcavg(), but there's no actual calcavg function ever written.
I assume that calcavg was a function you were going to write. Either it needs to be added to this file, or if it's in a different file, it needs to be compiled and linked as well.
//Definition of calcavg:
void calcavg(ifstream&indat,string&name,float&t1,float&t2,float&t3,float&t4,float&t5,float&avg)
{}
Dev C++ finally compiled the program, and only the cursor was display on the console window (which is fine, because I want my output in a file; not in the console window); however, when i opened my output file, I wound up with pages and pages of garbage text that made no sense. What am I doing wrong?
I can't tell exactly what you're trying to do, but I'll throw out a few comments that I have. These definitely won't fix all the problems in the code.
Perhaps you abbreviated in your last post. Putting braces "{ }" after what was the function prototype gets it to compile, but there's no code there to have it do anything.
Another issue is that where you define the floats all in one line, you're only initializing total to 0. The reason why you're seeing pages of garbage text is because t1-t5 and average are never initialized to 0, and aren't set by calcavg assuming your program does have the empty braces "{ }" without text in the body. This means that these floats will take whatever value is randomly in their memory spot when the program runs, which is garbage. Since they're never changed, that's what it's writing out.
I'm not sure what drive E is on your system, but you should have "E:\class..." instead of just "E:class..." (Note the missing "\")
Another thing to consider is that avg is a float. In calcgrade(), think through what happens when it's called when avg is 89.5.
These comments probably don't fix everything in there, but hopefully will get you pointed in the right direction.
I talked to my instructor and the problem was that there was not any code in the body of my calcavg function. Thank you for helping me. I appreciate it!