社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

python和函数返回[duplicate]

Rohit Verma • 6 年前 • 1231 次点击  

我正在尝试调试一个递归函数,该函数用于验证用户输入并在输入正常时返回一个值。函数如下所示:

double load_price()
{
    double price;

    Goods * tempGd = new Goods();

    cin >> price;

    while (!cin)
    {
        cin.clear();
#undef max
        std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
        cout << endl;
        cout << "You didn't enter a number. Do so, please: ";
        cin >> price;
    } // endwhile
    if (!tempGd->set_price(price))
    {
        cout << endl;
        cout << "The price " << red << "must not" << white << " be negative." << endl;
        cout << "Please, insert a new price: ";
        load_price();
    }
    else
    {
        delete tempGd;
        return price;
    }
}

方法set_price()的 货物 类如下所示

bool Goods::set_price(double price)
{
    if (price> 0)
    {
        priceSingle_ = price;
        priceTotal_ = price* amount_;
        return true;
    }
    return false;
}

我试着在纸上画出这个问题,但我所有的图表看起来都像我的函数。我认为退货有一些问题,但我不知道在哪里。

我们将非常感谢您的帮助。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43819
 
1231 次点击  
文章 [ 2 ]  |  最新文章 6 年前