Reputation: 1
So, I am supposed to make a program that asks for the value of a wholesale item, the percentage of which the item is marked up, and calculate and display the retail price using a function. The problem is I am explicitly supposed to prompt for a whole number, so if say the markup was 50%, the user should enter "50". Is there any way to just add a decimal point on the front of the 50 to simplify?
I'll include my code for clarity.
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;
}
Upvotes: 0
Views: 109
Reputation: 169038
"Move the decimal point two places to the left" is the same operation as "divide the number by 100."
markup /= 100;
Upvotes: 5