C++ C++;使用dowhile进行验证

C++ C++;使用dowhile进行验证,c++,validation,loops,do-while,C++,Validation,Loops,Do While,这是我的代码,但如果用户输入要检查的某个值,它会拾取错误,但会在无限循环中显示错误消息 std::cin >> withdrawAmount; do { if (withdrawAmount < balance && withdrawAmount > 0) { break; } std::cout << "Error: You have insufficie

这是我的代码,但如果用户输入要检查的某个值,它会拾取错误,但会在无限循环中显示错误消息

std::cin >> withdrawAmount;
    do
    {
        if (withdrawAmount < balance && withdrawAmount > 0)
        {
        break;
        }
    std::cout << "Error: You have insufficient balance to withdraw " << withdrawAmount << " pounds. Your balance is only " << balance << " pounds." << std::endl;
    std::cout << "Or you have entered a non positive integer" << std::endl;
    }
    while (true);

// some more code
std::cin>>提取金额;
做
{
如果(取款金额<余额和取款金额>0)
{
打破
}

std::cout对于您的主要问题,cin在循环之外,因此它只发生一次


对于第二个问题,在提取后调用std::cin的memeber函数。

好的,愚蠢的错误,cin在循环之外,修复了这个问题,但是仍然无法确定如何检查整数
std::cout << "Please enter todays date: (as an integer) ";
    do
    {
    std::cin >> date;   
        if (date > 1 && date < 31)
        {
        break;
        }
    std::cout << "Error: Please enter todays date: (as an integer) ";
    }
    while (true);

// some more code