Hello, well this program involves 2 self made header files and the main program file. its supposed to perform mathmatical operations with fractions, but after it promps and scans in the numbers from the user it stops working please help here is all the code:

Code:
```#include <iostream.h>
#ifndef fraction_h
#define fraction_h

class numbers
{
private:
int num, den, x, y;

public:
numbers(int num = 0, int den = 1);
void reduction();
numbers subtract(numbers, numbers);
numbers multiply(numbers, numbers);
numbers divide(numbers, numbers);
void printfrac();
void printdec();

};
#endif```
The second one, prints and peforms operations

Code:
```#include<iomanip.h>
#include<iostream.h>
#include"16-6.h"

numbers::numbers(int num, int den)
{
int x, y;
x = num;
y = den;
}

void numbers::printfrac()
{
cout << x << "/" << y; /* prints as fraction */
}

void numbers::printdec()
{

cout << dec /* prints in decimal form */
<< setprecision(3) << (float)x/y;
}
void numbers::reduction()		/* reduces fraction */
{
int i, small;
if (x < y)
small = x;
else
small = y;
for (i = small; 1 >= 1; i--)
if(x % i == 0 && y % i == 0)
{
y = y / i;
x = x / i;
}
}
numbers numbers::multiply(numbers one, numbers two)
{
int whole = 0;
numbers d;
d = one.x * two.y;
d.reduction();
return d;
}

numbers numbers::divide(numbers one, numbers two)
{
int whole = 0;
numbers d;
d = one.x * two.y; // invert and multiply
d = two.x * one.y;
d.reduction();
return d;
}

{
int t1 = 0, t2 = 0, temp_num1 = 0, temp_num2 = 0, temp_den1 = 0,
temp_den2 = 0, whole = 0;
numbers d;
t1 = one.y;
t2 = two.y;
temp_num1 = one.x * t2;
temp_den1 = one.y * t2;
temp_num2 = two.x * t1;
temp_den2 = two.y * t1;
d.x = temp_num1 + temp_num2;
d.y = temp_den1;
d.reduction();
return d;
}

numbers numbers::subtract(numbers one, numbers two)
{
int t1 = 0, t2 = 0, temp_num1 = 0, temp_num2 = 0, temp_den1 = 0,
temp_den2 = 0, whole = 0;
numbers d;
t1 = one.y;
t2 = two.y;
temp_num1 = one.x * t2;
temp_den1 = one.y * t2;
temp_num2 = two.x * t1;
temp_den2 = two.y * t1;
d.x = temp_num1 - temp_num2;
d.y = temp_den1;
d.reduction();
return d;
}```
Main program

Code:
```#include <iostream.h>
#include "student2n3.h"
#include "16-6.h"

int main()
{
int num, den;
numbers three(num = 0, den = 1);
cout << "Enter a fraction (ex. 4/5):  ";
cin >> num;
cin.ignore(80, '/');
cin >> den;
numbers one(num, den);

cout << "Enter a second fraction:  ";
cin >> num;
cin.ignore(80, '/');
cin >> den;
numbers two(num, den);
// This is where the program dies!!!!!!!!!!!!!!
one.printfrac();
cout << " + ";
two.printfrac();
cout << " = ";
three.printfrac();
cout << " = ";
three.printdec();

three = three.subtract(one, two);
one.printfrac();
cout << " - ";
two.printfrac();
cout << " = ";
three.printfrac();
cout << " = ";
three.printdec();

three = three.multiply(one, two);
one.printfrac();
cout << " * ";
two.printfrac();
cout << " = ";
three.printfrac();
cout << " = ";
three.printdec();

three = three.divide(one, two);
one.printfrac();
cout << " / ";
two.printfrac();
cout << " = ";
three.printfrac();
cout << " = ";
three.printdec();

one.printfrac();
cout << " = ";
one.printdec();

two.printfrac();
cout << " = ";
two.printdec();
}```
Thank you

2. Here's one problem, you're updating local variables x and y and not the ones in the class, so the class x and y remain uninitialised.

Remove int x, y;
Code:
```numbers::numbers(int num, int den)
{
x = num;
y = den;
}```

3. Well first a the class numbers should contain a num and den as data-members. You have no use of x and y in your example.

Code:
```numbers::numbers(int num, int den)
{
int x, y;//creates local variabels x and y
x = num;
y = den;
}```
This code creates 2 local variabels that is destroyed after the constructor exits. What you need to do is initialize data-members y and y like this.
Code:
```numbers::numbers(int num, int den):
this.num(num),this.den(den)
{}```
Also yours arithmaric operations need some fix (why not overloading appropriate operator(s)??) Insteed of
Code:
`three.add(one, two);`
Isnīt this more intuitive??
Code:
`three = one + two;`
Anyway this is a design issue, back to the errors .
The add/subtract/multiply/division member-function needs some modification. Iīm gonna show you how to fix one of them and leave the rest for you (itīs the same logic to them all).

Code:
```numbers numbers::add(numbers one, numbers two)
{
numbers d;
d.num = (one.num*two.den) +(two.num*one.den);
d.den = one.den*two.den
return d;
}```
If something is unclear, just ask .

4. ok i did what you guys said, but it still dies right after i enter in both fractions, and i dont know why

5. whoa man, thanks, something so simple

:-) thanks buddy

6. A saw some error in my previous code sorry
The constructor dont accept a this-pointer in its initialization list (there probably is one way around it but donīt have my book to check it)
Code:
```numbers::numbers(int num, int den):
this.num(num),this.den(den)
{}```
Compiles to an error, change it to something like
Code:
```numbers::numbers(int num, int den)
{
this->num = num;
this->den = den;
}```
Code:
```/* Also one and two should be passes as const-refernses to avoid unneccesasy copies of objects - but I leave it out for demonstation purposes*/
{
num = (one.num*two.den) +(two.num*one.den);
den = one.den*two.den;
}```
Here is some compensation for mine previous misstake
Code:
```#include <iostream>
#include <conio.h>//warining - nonstandard

using namespace std;

class numbers
{
private:
int num, den;

public:
numbers(int num, int den);
int getNum() const
{
return num;
}
int getDen() const
{
return den;
}
};

numbers::numbers(int num, int den)
{
this->num = num;
this->den = den;
}

{
num = (one.num*two.den) +(two.num*one.den);
den = one.den*two.den;
}

int main()
{
numbers one(5, 5);
numbers two(1, 25);
numbers three(0,0);