Using Constructors to compare/calc user input

We have this assignment form out teacher, a which is a bit confusing towards the end. "Define a class called Money. Your class will have two member variable of type int to represent dollar and cent values. Include all the following member functions: a constructor to set the dollar and cent using two integers as the arguments, a constructor to set the dollar using an integer as an argument (cent=0), a default constructor (dollars=0,cent=0), an output function that outputs the money with $ sign. Embed your class definition in a test program that asks the user to enter two Money values and compare them."

I have done everything it asks, but when it comes to the last bit I cannot figure out how weather to accept 2 dollars/cents inputs and then pass them to two instances of one of the overloaded constructors, but then it ins't clear how I compare the values then. Or weather to just to accept 1 dollar and 1 cent inputs then etc.

this is what i have so far
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <string>

using namespace std;

class money
{
private:
	int dollars;
	int cents;
public:
	money();
	money(int str);
	money(int str1, int str2);
	double displayMoney();
};

money::money()
{
	dollars = 0;
	cents = 0;
}
money::money(int str)
{
	dollars = str;
	cents = 0;
}
money::money(int str1, int str2)
{
	dollars = str1;
	cents = str2;
}

double money::displayMoney()
{
	double total = dollars + cents/(double)100;
	cout << "$" << total << endl;
	return total;
}




int main()
{

	int input11, input12, input21, input22;
	
	money c;

	cout << "Enter 2 money values: "<< endl;
	cout << "\n Dollars 1: ";
	cin >> input11;
	cout << " Cents 1: ";
	cin >> input12;

	cout << "\n Dollars 2: ";
	cin >> input21;
	cout << " Cents 2: ";
	cin >> input22;

	money x(input11, input12);
	money y(input21, input22);
	
/*	if(x.displayMoney() > y.displayMoney())
	{
		cout << "\n $" << x.displayMoney() << " is greater than " << "$" << y.displayMoney() << endl;
	}
	else if(x.displayMoney() < y.displayMoney())
	{
		cout << "\n $" << y.displayMoney() << " is greater than " << "$" << x.displayMoney() << endl;
	}
	else
	{
		cout << "\n $" << x.displayMoney() << " is equal to " << "$" << y.displayMoney() << endl;
	}*/


/*	if (input1 > 0 && input2 > 0)
	{
		money x(input1, input2);
		x.displayMoney();
	}
	else if (input2 <= 0 && input1 > 0)
	{
		money x(input1);
		x.displayMoney();
	}
	else
	{
		money x;
		x.displayMoney();
	}*/

	return 0;
}

From here I don't know how to get the last bit of work. commented out code was previous ideas of how to compare the values/use the different constructor based on user input
Last edited on
Topic archived. No new replies allowed.