I have a list of accounts (konton) where i save the values in a text file and use in a vector. And have to add a new customer to the existing/loaded list with this function, instead it erases the old list and I have to start a new one.
I don´t know why that is in that way, but when I starting from scratch with a new list there is no problem adding new holders to the bank and the new list started.
Wordlist:
konto = account
nummer = number
fnamn = firstname
enamn = lastname
saldo = debt
rantesats = interest
// And have to add a new customer to the existing/loaded list with this function, instead it erases the loaded list and I have to start a new one.
// I don´t know why that is in that way, but when I starting from scratch with a new list there is no problem adding new holders to the bank and
// the new list started:
void add_account(vector<Konto>&konton)
{
string fnamn;
string enamn;
int nummer;
double saldo;
double rantesats;
cout << "Skriv in kontonummer: " << flush << endl;
// Enter values into vector
cin >> nummer;
for(unsignedint i=0; i < konton.size(); i++)
{
if (nummer == konton[i].Nummer())
{
cout << "Konto existerar redan." << endl << endl;
return;
}
}
// Flush makes sure that the buffer is cleared and the characters are written to their destination
cout << endl << "Skriv namn p\x86 innehavaren av kontot: " << flush << endl << endl;
// Enter values into vector
cout << "Skriv in f\x94rnamn: " << endl;
cin >> fnamn;
cout << "Skriv in efternamn: " << endl;
cin >> enamn;
cout << endl << "Skriv in saldot: " << flush << endl;
// Enter values into vector
cout << "-";
cin >> saldo;
// Flush makes sure that the buffer is cleared and the characters are written to their destination
cout << endl << "Skriv in r\x84ntesatsen per \x86r i %: " << flush << endl;
// Enter values into vector
cin >> rantesats;
cout << endl;
cout << "Nytt konto skapat:" << endl;
cout << "Kontonummer: " << nummer << endl;
cout << "Namn: " << fnamn << " " << enamn << endl;
cout << "Saldo: -" << saldo << endl;
cout << "R\x84ntesats per \x86r i %: " << rantesats << "%" << endl << endl;
konton.push_back(Konto(nummer, fnamn, enamn, saldo, rantesats));
}
I suggest that you move the code that prints the konton array from load() to a separate print() function. Then call it at the end of add_account(). You should find that the new record shows up just fine. Sprinkle the rest of your code with calls to print() to find out where things are really going wrong.
Yes and it adds a new aoccount. But there is one problem with it. If a list is loaded from the text-file the void add_account(vector<Konto>&konton) erases the list and adds the new account over the deleted old ones. I need it to preserve the old list and keep the old list intact and add the new account to it. I can´t see why this code wouldn´t work for it? What am I doing wrong?
Found an error in the code. Yea! Alrigth and you gusy a couple of working functions. Thanks for the help! / P