94.1k views
5 votes
A size of a jumbo candy bar with rectangular shape is l x w x h. Due to rising costs of cocoa, the volume of the candy bar is to be reduced by p%.

To accomplish this, the management decided to keep the height of the candy bar the same, and reduce the length and width by the same amount.

For example, if l = 12, w = 7, h = 3, and p = 10, then the new dimension of the candy bar is 11.39 x 6.64 x 3.

Below is an example of how the completed program should work:

Enter the length, width, and height of the candy bar separated by space(s): 12 7 3

Enter the amount of the reduced volume as a percentage: 10

The new dimensions of the candy bar is: 11.38 x 6.64 x 3.00


Format your output with setprecision(2) to ensure the proper number of decimals for testing!

User Natan Cox
by
6.0k points

2 Answers

3 votes

Please wait until more research is discovered...

Question

A size of a jumbo candy bar with rectangular shape is l x w x h. Due to rising costs of cocoa, the volume of the candy bar is to be reduced by p%.

To accomplish this, the management decided to keep the height of the candy bar the same, and reduce the length and width by the same amount.

For example, if l = 12, w = 7, h = 3, and p = 10, then the new dimension of the candy bar is 11.39 x 6.64 x 3.

Below is an example of how the completed program should work:

Enter the length, width, and height of the candy bar separated by space(s): 12 7 3

Enter the amount of the reduced volume as a percentage: 10

The new dimensions of the candy bar is: 11.38 x 6.64 x 3.00

Format your output with setprecision(2) to ensure the proper number of decimals for testing!

User Justin Rhoades
by
5.9k points
2 votes

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.

User Ifyouseewendy
by
5.6k points