Dec 5, 2015 at 8:33pm UTC
The obvious guess is that the for
loop is skipped over. How do you know, absolutely for sure, that the for
loop is being entered?
Add some more debug output. On line 17, output the size of the vector konton
. On line 27, output some text so you know it's past the for
loop.
Last edited on Dec 5, 2015 at 8:36pm UTC
Dec 6, 2015 at 12:43pm UTC
Yes, the for-loop is skipped but I don´t know why. The konto.size() returns a zero. Test1, Test2, and Test3 is printed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
cout << "Test1" << endl;
BubbleSort(konton);
cout << "Test2" << endl;
for (unsigned int i = 0; i < konton.size(); i++)
{
cout << "Kontonummer: " << konton[i].Kontonummer() << endl;
cout << "Innehavare: " << konton[i].Innehavare() << endl;
cout << "Saldo: " << konton[i].Saldo() << endl;
cout << "R\x84ntesats: " << konton[i].Rantesats() << endl << endl;
}
cout << "\n" << endl;
cout << "Test3" << endl;
cout << konton.size() << endl;
Last edited on Dec 6, 2015 at 12:44pm UTC
Dec 6, 2015 at 12:45pm UTC
Your for
loop will keep looping as long as i
is less than the size of konton.
i
begins with a value of zero. konton
has a size of zero. So the first time, is i
less than zero? No, it is not. So how many times will we go around the for
loop? Zero times.
Dec 6, 2015 at 12:47pm UTC
Yes, the for -loop is skipped but I don´t know why. The konto.size() returns a zero
Your answer is in your question no?
If it returns 0, why would the for-loop run? Look at the condition.
for (unsigned int i = 0; i < konton.size(); i++)
0 is not bigger than 0, therefor this loop is obviously being skipped.
You need to find the source of the problem, which is why the size of konto is 0.
Dec 6, 2015 at 12:48pm UTC
konto's size is zero because it is explicitly emptied
konton.clear(); // Clear the contents of konton
and nothing gets put into it after that.
If I had to guess, the file bank.txt
is not in the working directory of the program.
Last edited on Dec 6, 2015 at 12:49pm UTC
Dec 6, 2015 at 6:49pm UTC
It seems like it is the while-loop
1 2 3 4
while (fin >> kontonummer >> innehavare >> saldo >> rantesats)
{
konton.push_back(Konto(kontonummer, innehavare, saldo, rantesats));
}
It doesnt start and I don´t know why.
Last edited on Dec 6, 2015 at 6:51pm UTC
Dec 6, 2015 at 6:52pm UTC
I expect because there's a problem with fin.
I expect because Bank.txt is not in the working directory of the program.
Last edited on Dec 6, 2015 at 6:53pm UTC