【问题标题】:My code is returning 0 when I compile why? [closed]编译时我的代码返回 0 为什么? [关闭]
【发布时间】:2015-04-21 01:14:36
【问题描述】:
int onedudetotal;
int total;
int cust;
int price;
int day;

double calculate(int avgcust, int avgprice, int days)
{
    onedudetotal = (avgprice * days) * avgcust;
    return onedudetotal;
};

int main()
{   
    cout << "Please enter days, average customers and days" << endl;
    cin >> cust; price; day;
    cout << calculate(cust, day, price) << endl;
}

在编译期间,我的代码在输入 day cust 和 price 时返回 0。输入 5、120 和 50 时应该返回 30000。可能是什么问题?

【问题讨论】:

  • cin &gt;&gt; cust &gt;&gt; price &gt;&gt; day;
  • 打开/打开编译器警告。

标签: c++ algorithm math


【解决方案1】:

你有:

cin >> cust; price; day;     // reads 'cust' from user input
                             // evaluates price, day as expressions
                             // which do nothing

你的意思是:

cin >> cust >> price >> day;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    相关资源
    最近更新 更多