我现在遇到的问题是我可以第一次输入随机的东西并且它工作正常,但在第二次尝试时它会输入错误的输入。例如:第一次输入国际象棋,它会说再试一次。第二次输入国际象棋它将接受国际象棋并打开检查然后将h放入存款金额导致错误重试
case 1:
cout << "Checking (C) or Savings (S): enter your choice" << endl;
cin.get(choice);
//input validation
while(choice != 'c' && choice != 'C' && choice != 's' && choice != 'S')
{
cin.clear();
cin.ignore(100, '\n');
cout << "Invalid input. Try again: ";
cin.get(choice);
}
//deposit in checking
if (choice == 'c' || choice == 'C')
{
cout << "how much are you depositing: $" << endl; //get deposit
cin >> deposit;
while(!(cin >> deposit)) //make sure user input is valid
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cout << "Invalid input. Try again: ";
}