This program takes the input for the length, width, height, and the percentage reduction in volume. It then calculates the reduction factor and applies it to the length and width to obtain the new dimensions.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
// Input dimensions
double l, w, h;
cout << "Enter the length, width, and height of the candy bar separated by space(s): ";
cin >> l >> w >> h;
// Input reduced volume percentage
double p;
cout << "Enter the amount of the reduced volume as a percentage: ";
cin >> p;
// Calculate the reduction factor
double reductionFactor = 1.0 - (p / 100.0);
// Calculate new dimensions
double newL = l * reductionFactor;
double newW = w * reductionFactor;
// Output the result with setprecision(2)
cout << fixed << setprecision(2);
cout << "The new dimensions of the candy bar is: " << newL << " x " << newW << " x " << h << endl;
return 0;
}
The output is formatted using setprecision(2) to display two decimal places.