Need Help With My Banking Program

This is a discussion on Need Help With My Banking Program within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <cstring> using namespace std; int main(){ int money; int withdrawal; int balance; int deposit; char string[9]; ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    2

    Question Need Help With My Banking Program

    Code:
    #include <iostream>
    #include <cstring>
    using namespace std;
    int main(){
        int money;
        int withdrawal;
        int balance;
        int deposit;
        char string[9];
        money=100;
        cout<<"Enter the type of transaction you would like to make (deposit or withdrawal)";
        cin.getline(string,9,'\n');
        if(strcmp ( string, "withdrawal") == 0){
        cout<<"Enter the amount of money you would like to withdraw: ";
        cin>>withdrawal;
        balance=money-withdrawal;
        cout<<"Your balance is "<<balance<<"\n";
        system("pause");
        }
        else if(strcmp ( string, "deposit") == 0){
         cout<<"Enter the amount of money you would like to deposit: ";
         cin>>deposit;
         balance=money+deposit;
         cout<<"Your balance is "<<balance<<"\n";
         system("pause");
         }
    }
    I can't seem to understand why this program wont allow me to enter a withdrawal. It only allows me to make a deposit.

    I'd appreciate your help,
    -pat3lbr0s2014-

  2. #2
    Registered User
    Join Date
    Oct 2009
    Posts
    117
    What does the program do when you enter withdrawal?

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340
    "withdrawal" has 10 letters, you only get 9. Plus you're not accounting for the null character.

    Switch to C++ strings so that you don't have to worry about the size of the string.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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