因此,我应该编写一个程序来询问批发项的价值,并使用函数计算和显示零售价。问题是,我应该显式地提示输入一个整数,所以如果假设加价是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 go
cost += markup * cost;
return cost;
}发布于 2017-10-08 07:54:56
“将小数点左移两位”与“将数字除以100”的操作相同。
markup /= 100;https://stackoverflow.com/questions/46626226
复制相似问题