# Thread: How to calculate minimum balance in simple banking system

1. ## How to calculate minimum balance in simple banking system

Hi all,

I'm fairly new to this forum, but I have read the homework policy and I believe that the following question is within the guidelines.

I'm trying to figure out how to store and print the minimum balance for an account. It gets confusing since I'm not allowed to use functions and arrays. This is my code for the banking system thus far:

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

int main(void) {

float balance = 2000.00, deposit, withdrawal, credit, debit;
int choice;

printf("Your current balance is \$&#37;.2f \n\n", balance);
printf("Transaction options: \n\n");
printf("1 - Deposit funds (credit transaction) \n");
printf("2 - Withdraw funds (debit transaction) \n");
printf("3 - Print statement of account \n");
printf("4 - Compute interest and exit \n\n");
scanf("%d", &choice);

while(choice != 4) {

if(choice==1) {
printf("\nHow much do you want to deposit?\n");
scanf("%f", &deposit);
credit = balance + deposit;
printf("Your current balance is %.2f \n\n", credit);
balance = credit;
}

else if(choice==2) {
printf("\nHow much do you want to withdraw?\n");
scanf("%f", &withdrawal);
debit = balance - withdrawal;
printf("Your current balance is \$%.2f \n\n", debit);
balance = debit;
}

else if(choice==3) {
printf("\nCurrent balance: \$%.2f\n\n", balance);
}

printf("Transaction options: \n\n");
printf("1 - Deposit funds (credit transaction) \n");
printf("2 - Withdraw funds (debit transaction) \n");
printf("3 - Print statement of account \n");
printf("4 - Compute interest and exit \n\n");
scanf("%d", &choice);

}

system("PAUSE");
}```
The value for the minimum balance would be printed under "Current balance: ..." when the user selects choice #3 (Print statement of account). I know that I will need another variable to store the minimum balance, but I'm not completely understanding the logic behind it. Can someone help me with this? I'm not necessarily asking for the code yet; I just want to understand how it is supposed to work. If I'm still lost, I would appreciate it if someone could show me the correct code. Thanks!

2. As I've come to know it, a minimum balance ia an arbitray amount set by the banking institution. Basically, an amount less than the minimum balance is not worth their expenses to maintain an account of that size. Hope this helps. Maybe you have some other definition that I am not aware of --- ask the prof to clarify.

3. Originally Posted by kcpilot
As I've come to know it, a minimum balance ia an arbitray amount set by the banking institution. Basically, an amount less than the minimum balance is not worth their expenses to maintain an account of that size. Hope this helps. Maybe you have some other definition that I am not aware of --- ask the prof to clarify.
I believe the meaning here is that you keep track of the "current" balance (starts out at 2000) and as transactions occur, you keep track of the lowest that the balance has ever gotten. But yeah, at first that's what I thought.

In order to do this, you of course need to have some variable to store the minimum balance. Whatever you call it, it will start out the same as the current balance, i.e. 2000. Whenever you process a transaction, check the new current balance with the value stored in this minimum balance variable. If it is less, then you simply need to reset the minimum balance value to the current balance.

4. Thanks alot kcpilot and hk_mp5kpdw! I figured out that all I needed was a simple "if" statement using a variable that is set to the initial balance. I appreciate the way you guys explained it instead of just giving me the answer. I can't tell you how many times people like yourselves have assisted me at this forum. DEFINATELY appreciate it...

I have one more question. I'm working on Part B of the program now, and for the life of me, I can't remember the code for a branching statement. If someone could show me how that works in pseudocode or maybe even explain it simply for me, I would appreciate it. Basically, I'm using the same banking system, but adding in dates. The branching statement I'm referring to would seperate the seven months that have 31 days from the 5 months that have only 30 days. Thanks!

5. Well, don't forget that Feb has either 28 or 29 days, not 30 (unless for simplicity, you just use 30 for Feb). I'm not sure what you mean by branching. If you need to perform some other work involving the days of the month, the easiest thing to do would be to create a subroutine to do that work, e.g., void interest(int days), or void interest(month). Since I'm not sure what you are doing with the days, I am only assuming you are calculating interest on the balance.