Failing to Pass values correctly

I'm trying to assign a fraction but when i run it its giving me an incredibly large number so guessing that its not being passed correctly.

It works fine when i assign it in FullFraction::FullFraction() but when i give it variables, thats when it bugs out. Below is the relevant code.

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  class FullFraction
	{
		int numerator;
		int denominator;
		int gcd(int x, int y);
	public:
		FullFraction();
		FullFraction(int n, int d);
		FullFraction add(FullFraction rop);
		FullFraction subtract(FullFraction rop);
		FullFraction multiply(FullFraction rop);
		FullFraction divide(FullFraction rop);
		int getNumerator() const;
		void setFullFraction(int num, int denom);
		int getDenominator() const;
		float getDecimal() const;
		std::string toString();
	};


	FullFraction::FullFraction()
	{
		/*********************************
			Incase nothing is set like:
			FullFraction f0;
			sets the fraction to 0/0
		*********************************/
		numerator = 0;
		denominator = 0;
	}

	//sends in the value of a numerator and denominator
	FullFraction::FullFraction(int n, int d)
	{
		int numerator, denominator;
		FullFraction::setFullFraction(numerator,denominator);
	}

	//gets value of numerator
	int FullFraction::getNumerator() const
	{
		return numerator;
	}

	//sets value of the fraction
	void FullFraction::setFullFraction(int num, int den)
	{
		numerator = num;
		denominator = den;
	}

	//gets the value of the denominator
	int FullFraction::getDenominator() const
	{
		return denominator;
	}
	static int assign_FullFraction()
	{
		FullFraction f0; //if nothing is initilized it would be null
		FullFraction f1(2, 2);
		FullFraction f2(2, 7);
		FullFraction f3(1, -3);
		cout << f1.toString() << " + " << f0.toString() << " = " << f1.add(f0).toString() << endl;
		cout << f0.toString() << " + " << f1.toString() << " = " << f0.add(f1).toString() << endl;
		
		return 0;
	}
Line 36 : You are passing uninitialized variables to setFullFraction function because these variables are uninitialized so they contain undefined values.

int numerator, denominator;

I think this is what you mean :

1
2
3
4
5
6
// Sends in the value of a numerator and denominator
FullFraction::FullFraction(int n, int d)
{
	int numerator, denominator;
	FullFraction::setFullFraction(n, d);
}
thank you....i really appreciate it
Topic archived. No new replies allowed.