I'm writing a program that needs to read user input into a string object. I'm using getline(cin, name), but when it gets to the prompt, I can type anything in and press enter, but it'll just go to the next line and the cursor will keep blinking, prompting for more input. Essentially, the prompt for input never seems to end, no matter how many characters I type or how many times I press enter. I don't even know if it's actually sending the input into the string object. What could be causing this?
This is the entirety of the main function so far (it's not complete, the switch-case will eventually have 6 options, but it compiles without error) The relevant section begins at switch case 1:
#include <string>
#include <array>
#include <iostream>
#include "stdlib.h"
#include "Bank.h" //My own class. There is also a Bank.cpp, but I won't include the code in these unless they're deemed relevant
using namespace std;
void displayAccountInfo(); //will retrieve info on bank object
void main()
{
int accsCreated = 0; //Keeps track of how many accounts have been created so far. Allows placement of pointer to new bank object at an empty array index.
int option = 0; //Stores the option chosen by the user. Used in switch-case. Also ends do-while loop when ==6.
Bank* accounts[10]; //Will hold pointers to each bank object created by user in sequential order. No more than 10 accounts will ever be created.
Bank* accpntr; //Will point to one of the Bank objects. Used to initialize a pointer to the object in the accounts[] array.
//begin Menu prompt
do
{
cout << "[1] Create Bank object with values for accountNumber, name, and balance." << endl;
cout << "[2] Create Bank object with no parameters." << endl;
cout << "[6] End program" << endl;
cin >> option;
//begin option branch:
switch (option)
{
case 1:
{
int num; //holds account number
string name; //will hold account name as string object for use in Bank constructor
double balance; //holds account balance
cout << endl << "Enter an account number: ";
cin >> num;
cout << endl << "Enter a name for the account: ";
cin.ignore(std::numeric_limits<std::streamsize>::max()); //clears cin's buffer so getline() does not get skipped
getline(cin,name);
cout << endl << "Enter the balance of the account: ";
cin >> balance;
cout << endl;
accpntr = new Bank(num, name, balance); //creates a new bank object with attributes and a reference to it
accounts[accsCreated] = accpntr; //adds pointer to new bank object to first empty spot in array
accsCreated++; //increments total of how many bank objects have been created/what index position of accounts[] to create the next one at
} break; //end case 1
case 2:
{
accpntr = new Bank(); //creates a new bank object with an accountNumber of 9999, an empty name attribute, and a balance value of zero.
accounts[accsCreated] = accpntr; //adds pointer to new bank object to first empty spot in array
accsCreated++; //increments total of how many bank objects have been created/what index position of accounts[] to create the next one at
} break; //end case 2
case 6:
{
cout << "Ending Program." << endl;
}
} //end switch-case block
}
while (option != 6); //end menu prompt when user chooses option 6.
//end menu block
} //end function main()