I am working on a program and this what I must do, Create a class based on TMoney. TMoney only contains three denominations, tdollars, twons (worth
1/5 or .2 of a dollar) and tpennies.
Create an array of three Tmoney objects. Use a loop to input data into each of the elements. Print out
the data for the second Tmoney entered.
● inputdata prompts the user for input and then stores the values they enter in the object
● outputdata prints the information stored in the object
I am stuck because I keep getting errors on my cin and couts, and the last cin is also giving me an error. Could someone please help me? Thanks to those who reply.
#include <iostream>
using namespace std;
class TMoney
{
private:
int tdollars ;
int twons;
int tpennies;
public:
TMoney():tdollars(0),twons(0),tpennies(0){}
void getinputdata();
cout << "Enter the number of tdollars you own:";
cin >> tdollars;
cout << "Enter the number of twons you own:";
cin >> twons;
cout << "Enter the number of tpennies you own:";
cin >> tpennies;
void outputdata();
};
int main()
{
const int size = 3; // Added this line so you can easily change the input for everything just changeing this
TMoney money[size];
int tdollars,twons,tpennies;
// Changed your declaration of the money variable
for (int j = 0; j < size; j++) // Changed the 3 to size
{
money[j].getinputdata(); // Added this
// Put all of this inside your getinputdata() function within the class.
// cout << "Enter the number of tdollars you own:";
// cin >> tdollars;
//cout << "Enter the number of twons you own:";
//cin >> twons;
//cout << "Enter the number of tpennies you own:";
//cin >> tpennies;
}
for (int j=0; j<1; j++)
{
cout << "You have tdollars," << " twons," << " tpennies." << endl;
cin >> money[size].outputdata;
}
return 0;
}