Thread: How to calculate minimum balance in simple banking system

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    31

    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");
        printf("Please indicate your option: \t");
        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");
          printf("Please indicate your option: \t");
          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!
    Last edited by 3MGFX; 10-05-2007 at 10:47 AM. Reason: mistake in spelling

  2. #2
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    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. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote 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.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    31
    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. #5
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    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.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I think 3MGFX is asking about a "switch" statement.

    I recently posted a method of sorting out how many days there are in a particular month - do a search for "leapyear days in month" and I'm sure you'll find that.

    Sometimes banks "cheat" on the calculation front and use 12 x 30 days as a year, so each month is assumed to have 30 days equally - not sure what happens to the 5 days left over.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 06-13-2005, 09:03 AM
  2. Replies: 3
    Last Post: 06-13-2005, 07:28 AM
  3. Making a Simple Database System
    By Speedy5 in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2003, 10:17 PM
  4. Azbia - a simple RPG game code
    By Unregistered in forum Game Programming
    Replies: 11
    Last Post: 05-03-2002, 06:59 PM
  5. Variable Allocation in a simple operating system
    By awkeller in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 02:26 PM