Sunday, July 12, 2009

[C++] Trying to add part of an array with another. [To find a total]?

I am trying to create a way to take information from three arrays and add only the values from the last part of the array together.





This is how I was trying to get it up.





order1 = carArray[0].getordervalue;


order2 = carArray[1].getordervalue;


order3 = carArray[2].getordervalue;





I am getting an error such as


error C2440: '=' : cannot convert from 'int (__thiscall Car::*)(void)' to 'int'


Conversion is a valid standard conversion, which can be performed implicitly or by use of static_cast, C-style cast or function-style cast





I've been searching for other ways to do this, but I can't seem to find one. Its going to end up being something easy that I am missing somehow.





If anyone has any suggestions or tips of how to fix it, it would help me greatly.





[Still working on trying to fix it myself, if I do I will edit this and show how.]

[C++] Trying to add part of an array with another. [To find a total]?
OK so here is how I would do it... If you are totaling the lets say first three elements in an array, use a for loop...





int total=0;


for(int i=0;i%26lt;3;i++)


total=carArray[i]+total;





that will put the total of the first three elements into the variable total.. then of course there are other variations that you can do with that basic Idea. good luck
Reply:Your error occurs because getordervalue is a function, not a variable. You still need to put parenthesis even if the function doesn't accept any parameters. Your format should be:





int order1 = carArray[0].getordervalue();





I think fixing this error should suffice for you to figure out the problem on your own =)


No comments:

Post a Comment