0

I'm working on a banking program, but I've come across a weird problem with

cin>> task;

It's supposed start up a switch. but it keeps skipping the input and ends the program.

I even have an example of this on hand, that code works, but this one doesn't I'm not sure what I'm doing wrong.

#include<iostream>
#include<conio.h>
#include<string>
#include <ctype.h>
using namespace     std;

int main()
{

    string name = "";
    int count;

    char task;
    double bal = 0;

    int depo, withd;
    cout << "Welcome to bank of the future! Please sign in" << endl;

    cin >> name;

    cout << "Enter your account number." << endl;
    cin >> count;
    cout << "Welcome back " << name << " What would you like to do?";

    cout << "\n A. Deposit \n B. Withdraw \n C. Show balance \n D. Quit" << endl;


    cin >> task;

    //just to check if it's being skipped over or not.
    cout << "egg " << endl;

    switch (task)
    {
    case 'A':
        cout << "Enter an amount to deposit" << endl;
        cin >> depo;
        cout << "Prevous balance: " << bal << endl;
        bal = bal + depo;
        cout << "New balance: " << bal << endl;
        break;

    case 'B':
        cout << "Enter an amount to withdraw" << endl;
        cin >> withd;
        cout << "Prevous balance: " << bal << endl;
        bal = bal - withd;
        cout << "New balance: " << bal << endl;
        break;
    case 'C':
        cout << "Your current balance is " << bal << "\n For account: " << name << "Acount number: " << count << endl;
        break;
    case 'D':
        cout << "Goodbye forever" << endl;
        break;

    }


    return 0;

}
amanuel2
  • 4,508
  • 4
  • 36
  • 67
  • [Why Not to use `using namespace std;`](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – amanuel2 Oct 09 '16 at 02:34
  • After the `cin >> name` there is a newline character left in the stream (you typed it!). That is read by the `cin >> task` - before the character you enter for the task is read. Give your `switch` a `case '\n' : ` and you'll see it. – Peter Oct 09 '16 at 02:38

1 Answers1

0

I think it may have to do with the char being upper or lower case. In the switch you specify that task is uppercase. When I tried your code with uppercase letters it worked for me, but when I entered a lowercase letter it ended the program.