|
-
Nov 12th, 2002, 02:28 PM
#1
Thread Starter
Stuck in the 80s
[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?
Last edited by The Hobo; Nov 12th, 2002 at 04:40 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|