# Data Flow through Classes

Page 1 of 1

## 2 Replies - 1072 Views - Last Post: 07 November 2007 - 06:50 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=36961&amp;s=22aa679f09672101051f8f9cae63897b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 0
• Posts: 3
• Joined: 05-September 07

# Data Flow through Classes

Posted 07 November 2007 - 02:18 AM

I'm having some trouble understanding the flow of data thru classes, and constructs this is the code i have so far
```#include <iostream>

using namespace std;

{
public:
void writeData(int result); //intializes function to cout result to user
};
class subData //class to declare subData construct
{
public:
subData(int inputSub[2]);
};
int main()
{
int i; //counter
subData Sub(int inputSub[2]); //adds data obtained from loop into the construct
int addSub;  //variable to determine to run thru add or subtract method
int inputSub[2];  //variables for subtract data

cout << "Press 1 to add 2 input numbers" << endl;
cout << "Press 2 to subtract 2 input numbers" << endl;

if(addSub == 1) //if option 1 is choosen
{
for(i = 0; i < 1; i++)//loop to obtain data and stores data on an array
{
cout << "Please enter number: " << i + 1 << endl;
}
}
if(addSub == 2) //if option 2 is chossen
{
for(i = 0; i < 1; i++) //loop to obtain data and stores data on an array
{
cout << "Please enter number: " << i + 1 << endl;
cin >> inputSub[i];
}
}
}
subData::subData(int inputSub[2])  //construct to subtract data
{
system("pause"); //only added so i could see if program was reaching this point or crashing before it
int result;
result = inputSub[0] - inputSub[1];
void writeData(int result);
}
{
system("pause"); //only added so i could see if program was reaching this point or crashing before it
int result;
void writeData(int result);
}
void writeData(int result)
{
cout << "The result is: " << result << endl;
system("pause"); //pauses so user can read result
}

```

the program will compile and run, but it crashes after it ask for first number input, project was due 2 days ago, been trying to work thru it myself but having little success, thx for your help.

Is This A Good Question/Topic? 0

## Replies To: Data Flow through Classes

### #2 William_Wilson

• lost in compilation

Reputation: 207
• Posts: 4,812
• Joined: 23-December 05

## Re: Data Flow through Classes

Posted 07 November 2007 - 05:46 AM

your code compiles and seems to work fine. The only advice i could offer was I added a return statement to your main method, since it is of type int, you really should return one. return 0;

Reputation: 0
• Posts: 3
• Joined: 05-September 07

## Re: Data Flow through Classes

Posted 07 November 2007 - 06:50 AM

William_Wilson, on 7 Nov, 2007 - 05:46 AM, said:

your code compiles and seems to work fine. The only advice i could offer was I added a return statement to your main method, since it is of type int, you really should return one. return 0;

I compiled it and ran it again just to make sure, and as soon as i entered the first number the program crashed, i added the "return 0;" statement ^.^, knew i was forgetting something... thx