# Thread: why is math not calculating properly

1. ## why is math not calculating properly

In my code, I cannot figure why it still is calculating wrong:

here is the execute:

BANK RECONCILIATION FOR: 10/21/98

Ending balance on statement:350
Enter Outstanding dep (or 0 to quit)>75
Enter outstanding dep (0 to quit)>20
Enter outstanding dep (0 to quit)>150
Enter outstanding dep (0 to quit)>25
Enter outstanding dep (0 to quit)>0
Outstanding withdrawal (or 0 to quit)>57.85
Enter withdrawal (0 to quit)>200
Enter withdrawal (0 to quit)>50
Enter withdrawal (0 to quit)>125.38
Enter withdrawal (0 to quit)>0

Why is this happening it should be: 186.77

Code:
```#include <stdio.h>

#define SENTINEL 0

float finbal, outdep, withdraw;

int main (void)

{

printf("BANK RECONCILIATION FOR: 10/21/98");

printf("\n\nEnding balance on statement:");
scanf ("%f", &finbal);

printf("Enter Outstanding dep (or %d to quit)>", SENTINEL);
scanf ("%f", &outdep);

while (outdep!= SENTINEL)
{

printf("Enter outstanding dep (%d to quit)>", SENTINEL);
scanf("%f", &outdep);
finbal = finbal + outdep;

}

printf("Outstanding withdrawal (or %d to quit)>", SENTINEL);
scanf ("%f", &withdraw);

while (withdraw!=SENTINEL)
{

printf("Enter withdrawal (%d to quit)>", SENTINEL);
scanf("%f", &withdraw);
finbal = finbal - withdraw;
}
/* the outstanding deposits and withdrawals, are already sub-totaled
into finbal. So this is all you need:
*/

printf("Your final balance in your checkbook should be \$ %.2f\n" , finbal);

return 0;

}```

2. Do you have any plans to add the first deposit and subtract the first withdrawal?

3. I do not understand.

4. The first deposit. You don't add it in, you go straight to asking for the second deposit.

The first withdrawal. You don't subtract it out, you go straight to asking for the second withdrawal.

5. I see what you mean but I do not know how to fix this

6. Order the three statements in your loop in the correct order (i.e., the first thing you must do is process the validated transaction, then print a prompt, then get input).

7. Originally Posted by kburyanek
I see what you mean but I do not know how to fix this
As long as you understand what each line does then this level of programming is barely any more complex than writing a simple recipe for baking a cake. If the recipe you create says to add dry ingreedients, ice the cake, allow it to cool, place it in oven, cook 40 minutes, and then add butter and egg, well you've gotten a few things horribly wrong. If however you can sort that kind of thing out, then you can figure out how to solve your problem, just give yourself some time to think about it.

If it really wont come to you then you're going to need to either get a good personal tutor, or reconsider why you're attempting to learn to program. Programming is not for everyone.

8. I posted a working version of his program in his other thread on this topic.

It doesn't need any more changes. The logic is "odd", but it works fine, within the accuracy of a float that isn't "normalized".

This version calculates wrong because he made the changes manually, and goofed.

Copy and paste - I double checked the corrected version that I posted up, and it's fine.

I changed it back to my original, It does work. Thank you. I made other changes that were commented on im the thread and that threw me way off.