Bank program won't run with a loop

This is a discussion on Bank program won't run with a loop within the C++ Programming forums, part of the General Programming Boards category; How can i get my program to run until it's told to exit? I want it to store the value ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    6

    Bank program won't run with a loop

    How can i get my program to run until it's told to exit? I want it to store the value that the user inputs and stay at that value until the user changes it again

    Code:
    //Bank program
    
    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main()
    {
    //Define Intergers
    
    int Selection = 0;
    float TransAmount = 0.0;
    float Balance = 0.0;
    
        cout << setw(15) << "ATM" << endl;
        cout << "1: " << "Open Account" << endl;
        cout << "2: " << "Deposit Funds" << endl;
        cout << "3: " << "Withdraw Funds" << endl;
        cout << "4: " << "Check Balance" << endl;
        cout << "5: " << "Exit" << endl;
        cout << "Make your selection: " << endl;
        cin >> Selection;
        cout << endl;
    
    if (Selection == 1) {
        cout << "Enter the amount to open your account with: ";
        cin >> TransAmount;
        cout << "Your new balance is: " << Balance + TransAmount << endl;
        cout << endl;
        }//End if
    
    if (Selection == 2) {
        cout << "Enter the amount you would like to deposit: ";
        cin >> TransAmount;
        cout << "Your new balance is: " << Balance + TransAmount << endl;
        cout << endl;
        }//End if
    
    if (Selection == 3) {
        cout << "Enter amount you would like to withdraw: ";
        cin >> TransAmount;
    
    if (TransAmount > Balance)
        cout << "Insufficient Funds" << endl;
    
    else
        cout << "Your new balance is: " << Balance - TransAmount << endl;
        }//End else
    
    if (Selection == 4) {
        cout << " Your balance is: " <<Balance << endl;
        }//End if
    
    
        }//End main function
    Last edited by Thoggle; 07-17-2010 at 02:25 AM.

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    There is no loop?

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    Also, you are never updating balance. You are simply printing out a new value, without actually ever changing it.

  4. #4
    Registered User
    Join Date
    Jul 2010
    Posts
    1

    Smile

    Not only this but also u huv to use the loop(do-while). To make ur program enable to ask the user to change the entered values of the user or to exit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Endless loop without program freeze
    By TuXaKoS in forum C Programming
    Replies: 22
    Last Post: 04-28-2010, 07:31 PM
  2. triggering another program to run using serial port
    By infineonintern in forum C++ Programming
    Replies: 3
    Last Post: 07-22-2009, 05:16 AM
  3. Replies: 18
    Last Post: 07-06-2009, 07:12 AM
  4. Replies: 5
    Last Post: 06-23-2009, 03:51 AM
  5. Timed loop in C program
    By bilmiyor in forum C Programming
    Replies: 10
    Last Post: 03-26-2008, 11:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21