only one variable prints

I was playing around with classes and functions and im not sure why this is incorrect. The output is 5 when their should also be a 6.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "stdafx.h"
#include <cstdio>
#include <iostream>
using namespace std;
class cat
{
public:
	int stat;
	int fat;
};
int ford()
{
	cat trip;
	trip.fat = 6;
	cout << trip.fat << "\n";
	system("PAUSE >null");
	return 0;
}
int main()
{
	cat hello;
	hello.stat = 5;
	cout << hello.stat;
	system("PAUSE >null");
	return 0;
}
It never outputs the 6 because you never call the ford() function in int main().

You need to add ford() in int main().
can i suggest structs if you are going to be making similar data structures to this example. classes have the benefit of having a private section which is usually used to place all the variables. example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream> 
//included library
class me{
private://variables here
    int a, b;
public://functions here
    int returnA(){return a;}
    int returnB(){return b;}
    me();
}
me::me(){//contructor; 
    int a = 10;
    int b = 10;
}
Topic archived. No new replies allowed.