### Struct def "does not refer to a value"

Attempting to get through Stanfords Programming Abstractions and the solution provided for problem two assignment one will not compile due to this error...

` statsT stats; `
Error is
statsT does not refer to a value. on line 25

Here is the full code.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263`` ``````#include #include #include using namespace std; int main(int argc, const char * argv[]) { struct statsT { int low; int high; double average; }; /* CalculateStatistics() * Usage: stats = CalculateStatistics(filename) * -------------------------------------------- * This function keeps track of the running low/high value * as it reads the file, as well as a total and a count to compute * the average when we're done */ statsT CalculateStatistics(string filename) { statsT stats; // Since we know scores are between 0 and 100, we can set low and // high to beyond their range. This way, the first update is // just like the rest. // Otherwise, we'd need a sentinel and a little more logic stats.low = 101; stats.high = -1; int total = 0; int count = 0; // Open a new filestream and make sure it worked ifstream in; in.open(filename.c_str()); if (in.fail()) Error("Couldn't read '" + filename + "'"); while(true) { int num; in >> num; // Check that we read successfully if (in.fail()) break; // Update or data if we need to if (num < stats.low) stats.low = num; if (num > stats.high) stats.high = num; total += num; count++; } // Don't forget to watch for integer division! stats.average = double(total)/count; // And make sure to close your files in.close(); return stats; }; return 0; } ``````

Here is a link to the assignments
http://see.stanford.edu/see/materials/icspacs106b/assignments.aspx
Last edited on
You cannot define a function inside of another function.
The problem comes from trying to define a function inside of another function, which is illegal.

You must define the function outside of main().
 ``123456789101112`` `````` //Function prototype. Let's everything below know that this function exists statsT Calculate Statistics(string filename); int main(){ //... } //Function definition statsT Calculate Statistics(string filename){ //... } ``````

Now considering your CalculateStatics() function has to be outside of main(), this means you're going to need to move your statsT struct outside as well.

Random note:
You don't need semi-colons after a function definition.
Welcome, Bdanielz!

I hope you find what you are looking for!
I am glad you are using code tags, because many new users don't. :)
Topic archived. No new replies allowed.