Hey im having trouble, this is only the second program ive dont in c++, anyhow, its a group project for school dealing with math with fractions, here is the code for my header file:
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 a, numbers b)
{
int whole = 0;
numbers d;
d = a.x * b.y;
d.reduction();
return d;
}
numbers numbers::divide(numbers a, numbers b)
{
int whole = 0;
numbers d;
d = a.x * b.y; // invert and multiply
d = b.x * a.y;
d.reduction();
return d;
}
numbers numbers::add(numbers a, numbers b)
{
int t1 = 0, t2 = 0, temp_num1 = 0, temp_num2 = 0, temp_den1 = 0,
temp_den2 = 0, whole = 0;
numbers d;
t1 = a.y;
t2 = b.y;
temp_num1 = a.x * t2;
temp_den1 = a.y * t2;
temp_num2 = b.x * t1;
temp_den2 = b.y * t1;
d.x = temp_num1 + temp_num2;
d.y = temp_den1;
d.reduction();
return d;
}
numbers numbers::subtract(numbers a, numbers b)
{
int t1 = 0, t2 = 0, temp_num1 = 0, temp_num2 = 0, temp_den1 = 0,
temp_den2 = 0, whole = 0;
numbers d;
t1 = a.y;
t2 = b.y;
temp_num1 = a.x * t2;
temp_den1 = a.y * t2;
temp_num2 = b.x * t1;
temp_den2 = b.y * t1;
d.x = temp_num1 - temp_num2;
d.y = temp_den1;
d.reduction();
return d;
}
here are the errors i get
"student2n3.h", line 18.11: 1540-0274 (S) The name lookup for "x" did not find a declaration.
"student2n3.h", line 18.23: 1540-0274 (S) The name lookup for "y" did not find a declaration.
"student2n3.h", line 25.37: 1540-0274 (S) The name lookup for "x" did not find a declaration.
"student2n3.h", line 25.39: 1540-0274 (S) The name lookup for "y" did not find a declaration.
"student2n3.h", line 35.18: 1540-0064 (S) Syntax error: ")" was expected but ";" was found.
"student2n3.h", line 45.8: 1540-0217 (S) "x" is not a member of "class numbers".
"student2n3.h", line 45.14: 1540-0217 (S) "y" is not a member of "class numbers".
"student2n3.h", line 54.8: 1540-0217 (S) "x" is not a member of "class numbers".
"student2n3.h", line 54.14: 1540-0217 (S) "y" is not a member of "class numbers".
"student2n3.h", line 55.8: 1540-0217 (S) "x" is not a member of "class numbers".
"student2n3.h", line 55.14: 1540-0217 (S) "y" is not a member of "class numbers".
"student2n3.h", line 65.9: 1540-0217 (S) "y" is not a member of "class numbers".
"student2n3.h", line 66.9: 1540-0217 (S) "y" is not a member of "class numbers".
"student2n3.h", line 67.16: 1540-0217 (S) "x" is not a member of "class numbers".
"student2n3.h", line 68.16: 1540-0217 (S) "y" is not a member of "class numbers".
"student2n3.h", line 69.16: 1540-0217 (S) "x" is not a member of "class numbers".
"student2n3.h", line 70.16: 1540-0217 (S) "y" is not a member of "class numbers".
"student2n3.h", line 71.4: 1540-0217 (S) "x" is not a member of "class numbers".
"student2n3.h", line 72.4: 1540-0217 (S) "y" is not a member of "class numbers".
"student2n3.h", line 82.9: 1540-0217 (S) "y" is not a member of "class numbers".
"student2n3.h", line 83.9: 1540-0217 (S) "y" is not a member of "class numbers".
"student2n3.h", line 84.16: 1540-0217 (S) "x" is not a member of "class numbers".
"student2n3.h", line 85.16: 1540-0217 (S) "y" is not a member of "class numbers".
"student2n3.h", line 86.16: 1540-0217 (S) "x" is not a member of "class numbers".
"student2n3.h", line 87.16: 1540-0217 (S) "y" is not a member of "class numbers".
"student2n3.h", line 88.4: 1540-0217 (S) "x" is not a member of "class numbers".
"student2n3.h", line 89.4: 1540-0217 (S) "y" is not a member of "class numbers".
if i need to post the other header files or the main program for my question to be answered let me know, but what am i doing wrong?
Thanks in advance
EDIT::: where it makes the happy face, its because it is ": p" sorry