If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Looking for a Mentor

Code:

int openFile();

This is a function declaration for a function that takes no arguments and returns an int. It's not a function call. As openFile is defined after it is going to be used, openFile needs to have a forward declaration before it is used so the compiler knows what arguments it takes and the return type if any. This function declaration would be

Code:

int openFile(ifstream& inFile);

and usually function declarations are placed near the beginning of the program.

To call openFile you would use

Code:

openFile(inFile);

openFile is defined as returning an int but the function definition doesn't return any value. What value do you want the function to return if the open succeeds and what value if the open fails? Then when you call the function you should test its return value to check whether the function succeeded or failed.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: Looking for a Mentor

I changed it to void openFile() since it doesn't return a value really, just a statement

openfile() really should return some value to indicate that the file has been opened properly oe not which is checked for in the calling program. One possibility is have bool openfile() which returns true if the file opened or false if it did not.

However, my getLine is putting the whole line into a string. How do I parse that string into the 3 variables I need?

Rather than getLine putting the whole line into a string, why not just extract the 3 parts direct via stream extraction (eg as I did in my example program is post #21). Something like

Code:

infile >> first >> second >> third;

You can parse the getLIne string into the 3 parts yourself, but its much simpler/easier just to extract them direct from the file.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Re: Looking for a Mentor

Thanks! I keep posting questions and then figuring out how to get past them. Hahaha. I've gotten as far as writing data to my array but for some reason the loop is running 1 too many times and giving an extra value in each array that is something like 3.49e-59.

Re: Looking for a Mentor

You are using the == conditon where I think you want the = assignment. What does minCharges() function return?

When you create an enum type, the elements are assigned consecutive numbers starting at 0 (unless specified otherwise). So LOW is 0, HIGH is 1 and AVERAGE is 2. You are defining the arrays as having 2 elements (access 0 and 1) but then access using 2 (AVERAGE) so you have a memory buffer overflow as you are accessing memory outside that reserved for the arrays.

You'll also need to change the definiton of autoStats etc from charges to double. Having autoStats an array of charges means that the array elements can only take the values of the type charges (ie LOW HIGH or AVERAGE) which doesn't look like is what you want.

Last edited by 2kaud; January 19th, 2014 at 07:08 PM.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.