这是我的代码。当我运行我的代码并选择='n'时,执行createAccount()函数,但它不等待用户输入,否则显示此输出Code Output image
#include <iostream>
using namespace std;
string customerName;
string username;
string password;
double withdrawMoneyAmount;
double dipositMoneyAmount;
void createAccount();
int main()
{
cout << "Welcome to X Bank" << endl;
cout << "Do you have any Account here? (y/n) -> ";
char choice;
cin >> choice;
switch (choice)
{
case 'y':
// something will happen
break;
case 'n':
createAccount();
break;
default:
cout << "Please enter option correctly";
break;
}
}
void createAccount()
{
cout << "Enter your name ";
getline(cin, customerName);
cout << customerName;
}