小编Ste*_*eve的帖子

C++是否可以在数字的开头添加小数点?

所以,我应该制作一个程序,询问批发商品的价值,商品被标记的百分比,并使用函数计算和显示零售价格.问题是我明确应该提示一个整数,所以如果说标记是50%,用户应该输入"50".有没有办法在50的正面添加一个小数点来简化?

为了清楚起见,我会包含我的代码.

int main() {

    double cost;
    double markup;
    double total;

    cout << "Enter the item's wholesale cost: ";
    cin >> cost;
    cout << "\nEnter the item's markup percentage: ";
    cin >> markup;
    cout << endl;

    total = calculateRetail(cost, markup);

    cout << fixed << showpoint << setprecision(2);

    cout << "The item's retail price is $" << total << endl;

    return 0;
}

double calculateRetail(double cost, double markup)
{

    //This is where the code to convert "markup" to a decimal would …
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
36
查看次数

标签 统计

c++ ×1