Re: Displaying the contents of a vector

Posted 27 September 2012 - 10:43 PM

I guess I am still doing this wrong... I seem to be only storing the most recent values in my vector. I am not sure where my logic is incorrect. I am trying to store multiple objects in my vector. Any help would be greatly appreciated. Code is below:

Notice that in your member function you have variables with the same names as your class variables. This will cause the class member variables to be "hidden" by these parameters. This because the parameter variables are different variables than the class member variables, even though they have the same names. And because of this you will not modify your class member variables because the program is using the variables you passed into the function. So when the function exits any changes to these variables in the function will be lost. There are ways to force using the class variables in this case, but in my opinion it is better not do this.

Also, in my opinion, when you declare a function you shouldn't remove the variable names. Instead make the function prototype look the same as the function implementation.

Notice how the parameter names differ from the class variables. Also as already noted by baavgai you probably shouldn't be passing parameters into this function at all because you want to use the member variables, not the parameters.

Next you should get into a habit of always explicitly specifying the public, private, and protected access areas instead of relying on the defaults.

Re: Displaying the contents of a vector

Posted 30 September 2012 - 12:31 AM

I was working on the code again. Got the vector to display correctly. Now I am trying to compare bidPrice with the offerPrice, but I can't seem to assign it a value not sure what I am doing wrong. Here is the code below:

Re: Displaying the contents of a vector

Posted 30 September 2012 - 03:35 AM

Do you want to set an offer price for each element in the vector, or do you just want to store 1 offer price to compare with the vector. If you want to store multiple offer price in the vector you should use .at().

Re: Displaying the contents of a vector

Posted 30 September 2012 - 08:42 PM

Actually no I just wanted one offerPrice. I believe I have solved that part. However, what I would like to solve now is to let the trade know it has been executed. I would like to do this without setting up a global counter variable, but not sure of the proper way to do this. I have commented the line where I needed help. Any help would be greatly appreciated. Rethc, I am trying to do what you suggested but only for the executed variable. Thanks.

Re: Displaying the contents of a vector

Posted 06 October 2012 - 11:44 PM

I have fixed the above problem, but I am having logic problems with one of my functions. Specifically the checkList function. I want to compare prices to execute a trade...but my logic is flawed. I think it pertains to the line I have commented. Any help would be greatly appreciated.

Re: Displaying the contents of a vector

Posted 07 October 2012 - 04:42 AM

Your use of global variables, in particular salesOrder makes your code very confusing. I suggest redesigning so that you don't need that global, and you pass in the appropriate values for comparison instead.

Re: Displaying the contents of a vector

Posted 07 October 2012 - 01:21 PM

Skydiver, on 07 October 2012 - 04:42 AM, said:

Your use of global variables, in particular salesOrder makes your code very confusing. I suggest redesigning so that you don't need that global, and you pass in the appropriate values for comparison instead.

Unfortunately, the deadline for the project is tomorrow. I would not be able to re-design it. Any suggestions on how to make the checkList function function as it is?

Re: Displaying the contents of a vector

Posted 07 October 2012 - 01:51 PM

If you refuse to take the advise and stop using the global variables you must stop passing these global variables into your functions. When you pass a variable into your function that has the same name as your global variable you will use the variable you pass as a parameter, not the global. Even though they have the same name they are not the same variable.

I suggest you take the advise given and stop using the global variables, and learn to pass the variables correctly.