FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Okay need help with passing structures by reference KoM

   
Author Topic: Okay need help with passing structures by reference KoM
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
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.

IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
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 ]

IP: Logged | Report this post to a Moderator
ricree101
Member
Member # 7749

 - posted      Profile for ricree101   Email ricree101         Edit/Delete Post 
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?

Posts: 2437 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
ricree101
Member
Member # 7749

 - posted      Profile for ricree101   Email ricree101         Edit/Delete Post 
oops, double post, sorry
Posts: 2437 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
negative deals with negative numbers entered, positiv vice versa.
IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
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?
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
i passed psuodo code, I only wanted help with passing structures, and it works fine now, im onto version 5ish now out of 6.
IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

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