Thread: ATM C++ Case Help.

  1. #1
    Registered User GrafixFairy's Avatar
    Join Date
    Mar 2014
    Posts
    45

    ATM C++ Case Help.

    Can someone please assist me, Im having difficulties with this switch statement, instructions are below.

    If the user enters 2 to make a withdrawal, the user will be prompted to enter an amount or type
    0 (zero) to return to the main menu.
    a. If the withdrawal amount is greater than the account balance, the screen will display an
    error message stating this and prompts them to enter a smaller amount.
    b. If the withdrawal amount can be satisfied, carry out the transaction, display the new balance and return to the main menu.

    Code:
            case 2: cout << "Please Enter sum you wish to withdraw from account" << endl;
                cin >> withdraw;
            
            if ( withdraw > balance){
               cout << "Value Exceeds Current balance \n" << endl;
               cout << "please enter new amount or type 0 to return to menu" <<endl;
               cin >> withdraw;
               }   
                   if (input == 0){
                   return 0;
                   }
         
                balance = balance - withdraw;{
                cout << " You Have Withdrawn" << withdraw << "From your Accout" << endl;
                cout << " Balance is now" << balance << endl;
            }
              break;

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Do you have some kind of question?

    Jim

  3. #3
    Registered User GrafixFairy's Avatar
    Join Date
    Mar 2014
    Posts
    45
    How to i get it to clear screen and return to the menu when 0 is entered ?

  4. #4
    Registered User GrafixFairy's Avatar
    Join Date
    Mar 2014
    Posts
    45
    im trying to do an if statement but i dont know how to write it... if withdrawal > balance it should say it exxceeds amount and it should prompt the user to enter a new amount or 0 to return to the menu. if 0 is entered i want it to clear screen and start from the top.
    Code:
      cout << "      MENU         ";
      cout << "1. Balance inquiry \n";
      cout << "2. Withdrawal \n ";
      cout << "3. Deposit \n";
      cout << "4. Type -69 to Exit";
      cout << " type 0 to return to menu";
      cout << "Please Enter Choice \n";
      cin >> input;
      
      while (input != -69){

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    First make a flow chart. You need to understand the flow first.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    How to i get it to clear screen and return to the menu when 0 is entered ?
    How can I tell? The snippets haven't shown enough content to really show anything about your program.

    I recommend you post your complete program, then maybe someone can be of assistance.

    But as far as to clear the screen, there is really no standard way to accomplish this. There are operating system specific, or other libraries that can accomplish this but I recommend you just stick to standard functions and not worry about clearing the screen.

    Jim

  7. #7
    Registered User GrafixFairy's Avatar
    Join Date
    Mar 2014
    Posts
    45
    this is it..its very messy .
    Code:
            case 2: cout << "Please Enter sum you wish to withdraw from account" << endl;
                cin >> withdraw;
            
            if( withdraw > balance){
       cout << "Value Exceeds Current balance \n" << endl;
       cout << "please enter new amount or type 0 to return to menu" <<endl;
       cin >> withdraw;
       }   
           if (input == 0){
           return 0;
           }
              break;
    Last edited by GrafixFairy; 03-08-2014 at 09:53 AM.

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    this is it..its very messy .
    Yes, very. Maybe you should think about cleaning it up. In the process you may also want to consider the use of functions and some of the different loop constructs. And as already pointed out you need to sit down, away from the computer, and actually plan out the functionality of your program. And remember before you even start writing your program you must throughly understand the problem. The use of flow charts and pseudo code should be of a great help.

    Jim

  9. #9
    Registered User GrafixFairy's Avatar
    Join Date
    Mar 2014
    Posts
    45
    Ok, i going to draw up a flow chart and figure it out

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 08-25-2008, 12:01 PM
  2. case/if
    By Bingo The Clown in forum C++ Programming
    Replies: 7
    Last Post: 11-27-2003, 11:38 PM
  3. upper case to lower case problem
    By Jasonymk in forum C++ Programming
    Replies: 3
    Last Post: 04-27-2003, 05:35 AM
  4. How about using case ?
    By Adisonz in forum C Programming
    Replies: 1
    Last Post: 12-23-2001, 10:55 PM
  5. Case 2
    By iain in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-07-2001, 08:12 AM

Tags for this Thread