[Resolved] Classy Vector Help
I'm trying to run this code (I slimmed it down as much as I could):
Code:
#include <iostream>
#include <vector>
using namespace std;
class trans {
private:
vector<double> amount;
vector<char*> notes;
double total;
public:
//constructor:
trans() {
total = 0;
}
//destructor:
~trans() { }
//add a transaction:
void add(double a, char note[]) {
amount.push_back(a);
notes.push_back(note);
total += a;
}
//get number of transactions:
int getnumtrans() {
return amount.size();
}
//get transaction notes:
char *getnote(int index) {
return notes[index];
}
};
int main() {
trans deposits;
char con = '\0', comment[255];
double amount;
do {
cout << "Amount: ";
cin >> amount;
cout << "Comment: ";
cin >> ws;
cin.getline(comment, 255, '\n');
deposits.add(amount, comment);
cout << "Add another? (y) or (n): ";
cin >> con;
} while (con != 'N' && con != 'n');
for (int i = 0; i < deposits.getnumtrans(); i++) {
cout << deposits.getnote(i) << endl;
}
return 0;
}
For a bank account program. Insert deposit amount and deposit comment, continue, etc.
I do this a few times, entering unique comments such as 'Birthday Money', 'Paycheck', and 'None'
However, when it runs the loop to repeat all the comments, it just repeats 'None' three times.
Where am I going wrong with this?