Program stopping during runtime...

This is my code on a simulation of a Bank that has 10 people that manage the account:
http://pastebin.com/SN4TFhcH

I decided to add the feature of taking loans at random times and added a number of function to calculate the Interest, the total amount of money owed, and the random chances of returning that money.

The program has a bit too many loops though, making it harder to find the source of the error.

The problem is this:
The program does not complete the 600 iterations in the loop on line 555.
There is no specific number of iterations it will run, it can be that it stops on the first, and I have seen it reach completion once (only once).

This has made me reach the conclusion that there must be some loop that is not reaching completion for some specific values. I had encountered the same error earlier when there were no Loans.
I had made a mistake with the greater than sign rather than less than sign that would have triggered an if statement to break an infinite loop.

I can't seem to find the point of error this time. I am sure the error appeared after I added the Loan functions.

I have been at this for hours, but to no avail!

Any help?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
long  Amount(int i) //this was causing an infinite loop
{
	long int a, b, c, d, s;
	while(true)
	{
		a = (rand()%10) * 1000;
		b = (rand()%10) * 100;
		c = (rand()%10) * 10;
		d = (rand()%10);
		s = a+b+c+d;
		if (s < customer[i].Account.rBalance() && (customer[i].Account.rBalance()-s) > 500)
			break;
		else if ((customer[i].Account.rBalance()-s) > 500) //this can never happen. 
		{
			s = 0;
			break;
		}
	}

	return s;
}


Also, use std::swap instead of that xor/plus trick.

When posting code, please post the relevant parts. You've got ~ 300 lines of system dependant code, that shouldn't affect your program.
Last edited on
Thanks! That did the work.
I just can't figure out why customer[i].Account.rBalance()-s) > 500 would never happen?
I figured that I would use this to ensure that there is at least 500 in each account.


The swap is an old one I had. I have already removed it from the Header (Didn't mess with this one though). When I made this program I hadn't known about the existence of std::swap!

I had put the code a while back on there just to have a backup of the source code in case I get my PC infected and need to format it(has happened before, and a Quiz I had made was lost!)
I just updated it.
Though what you say is true. I will just make another post hence forth.

Thanks a Lot!!!

EDIT: Figured it out!
Last edited on
(customer[i].Account.rBalance()-s) > 500 for that be true, then s must be lower than rBalance() (which is the first test)
It is p -> q.
if(q and p) reduces to if(p) so your test is

if( p )
else if( p ) //can never happen

in case I get my PC infected and need to format it
That shouldn't be considered a solution...
in case I get my PC infected and need to format it

That shouldn't be considered a solution...

I said this because last time, the virus damaged the boot files , and repairing them wasn't working, the virus would damage them again!
So Formatting was the last resort...
Last edited on
Topic archived. No new replies allowed.