This is topic Okay need help with passing structures by reference KoM in forum Books, Films, Food and Culture at Hatrack River Forum.


To visit this topic, use this URL:
http://www.hatrack.com/ubb/main/ultimatebb.php?ubb=get_topic;f=2;t=045911

Posted by Blayne Bradley (Member # 8565) on :
 
okay so as a global i elcare

code:
struct catstats
{

int c; // count of items
float t; // total of items

};


and then in main

void main()
{

catstats n, p; //positive and negative catstat structures



cin >> num;

x_positive( num, structure& p? );
x_negative( num, structure& n?
}

Okay so I think n and p makes it that there's 2 separate structures declared for 'positive' and negative numbers, but I'm trying to figure out how do I pass the structures by reference.


Like in x_positive I want to calc the 'counter' and the 'total' of the pos/neg #'s I passed.


example:

code:
void x_positive( anum, structure& p? )
{


c++;
t = t + anum;

PrintCat();

}

Like if the variables are already declared in the struct catstates, how do I get it so that they're passed right? I thought func( num, catstats& p )

did it but apparently not.
 
Posted by Blayne Bradley (Member # 8565) on :
 
okay I think I figured it out I can do catstats p.c

:edit:

blah full or errors.

:double edit: okay now I think I gots it wokring

[ November 08, 2006, 10:27 AM: Message edited by: Blayne Bradley ]
 
Posted by ricree101 (Member # 7749) on :
 
I'm not sure if you still need the help, but here's two things that are coming to mind in your code.
In your function I don't think you are actually changing any members of p. I'm not totally sure why this would compile in the first place, but you should be doing p.c++ and p.t+= anum or some such thing.

Also, what is x_negative going that requires a separate function?
 
Posted by ricree101 (Member # 7749) on :
 
oops, double post, sorry
 
Posted by Blayne Bradley (Member # 8565) on :
 
negative deals with negative numbers entered, positiv vice versa.
 
Posted by King of Men (Member # 6684) on :
 
Not according to the code you posted. There's no check anywhere to ensure that only positive numbers get passed to x_positive. What's this code supposed to do, anyway?
 
Posted by Blayne Bradley (Member # 8565) on :
 
i passed psuodo code, I only wanted help with passing structures, and it works fine now, im onto version 5ish now out of 6.
 


Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2