The program is supposed to read transactions from a file and calculate who owes money to whom. But it should be possible to add a transaction through the keyboard. The code works fine when reading from a file (the calculations are correct and all) but adding a transaction through the keyboard does not work and I don't know why.
case 1:
{
cout << "Add transaction: " << endl;
cin.ignore(); // Ignores Enter
getline(cin, str); // reads a transaction (ex, 211105 food Nate 200 2 Walter Pete)
stringstream stream(str);
translist.read(stream);
break;
}
void TransactionList::read(istream& is) {
Transaction t;
while (t.readTrans(is)) {
addTrans(t);
}
}
bool Transaction::readTrans(istream& is) {
is >> date >> type >> name >> amount >> num_friends;
for (int i = 0; i < num_friends; i++) {
is >> friends[i];
}
return !is.eof();
}
void TransactionList::addTrans(Transaction& t) {
trans[num_trans] = t;
num_Trans++;
}
int main() {
ifstream infil("transactions.txt"); //reads from a file
ofstream utfil("a.txt");
TransactionList translist; // Declaring an array of all the transactions
translist.read(infil); //sending the stream to the read-function
translist.print(utfil);
PersonList personlist = translista.FixPersons(); // Makes some calculations etc
menu();
options(translista, personlista); //a function with some cases (see case 1 at the top)
return 0;
}