Why does the 'getline(cin, ownerName);' and the 'cin >> ownerName;' cause the user to be kicked out of the program. It continues to print the 'cout' statements but allows no more input.
#include <iostream>
#include <string>
using namespace std;
class SavingsAccount
{
int accountType;
string ownerName;
long ssn;
double accountClosurePenaltyPercent, accountBalance;
public:
void getValues();
void printValues();
inline double calcAcctPen() {return(accountBalance * accountClosurePenaltyPercent);}
};
int main()
{
SavingsAccount *Account1 = new SavingsAccount;
Account1->getValues();
cout << "The amount of the closure penalty is " << Account1->calcAcctPen() << endl;
Account1->printValues();
return 0;
}
void SavingsAccount::getValues()
{
cout << "Enter your account type ( 1 for checking, 2 for savings, 3 for IRA ): ";
cin >> accountType;
cout << "\nEnter your name ";
getline(cin, ownerName); // cin >> ownerName;
cout << "\nEnter your ss number ";
cin >> ssn;
cout << "\nEnter your account balance ";
cin >> accountBalance;
cout << "\nEnter the account Closure Penalty Percent ";
cin >> accountClosurePenaltyPercent;
cout << endl;
return;
}
void SavingsAccount::printValues()
{
cout << "Account type: " << accountType << endl;
cout << "Name on account: " << ownerName << endl;
cout << "Social Security Number: " << ssn << endl;
cout << "Account closure penalty percent: " << accountClosurePenaltyPercent << endl;
cout << "Account balance: " << accountBalance << endl;
return;
}