Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to calculate the cost of making a rectangular steel box. The pro

ID: 3669286 • Letter: W

Question

Write a program to calculate the cost of making a rectangular steel box. The program should read in the desired length l_box, the width w_box, and the height h_box, and the cost in Euro per square centimetres of steel, c. Assume that there is 2% wastage in the manufacturing process (in other words, the amount of steel needed is 2% more than the actual surface area of the box). The program should print the total cost in Euro of manufacturing the steel box, and the wastage cost in Euro associated with this box.

Make sure that all length, height, width and cost are larger than 0. Print the error message "Values must be larger than 0" otherwise. See the example.

Hint: to read properly the input with scanf, you have to respect the specific format of the input which is in this case "length=%d height=%d width=%d cost=%d"

Explanation / Answer

#include<iostream>

using namespace std;

int main()

{   float width,height,length,area,perUnit,totalCost;
   cout<<"Enter Width of Rectangle = ";
   cin>>width;
   cout<<"Enter Height of Rectangle = ";
   cin>>height;
   cout<<"Enter length of Rectangle = ";
   cin>>length;
   if(length <=0 || height <=0 || width <=0){
       cout<<"Please enter >0 "<<endl;
       return 0;
       }
  
   area = height*width*length;
   cout<<"Enter cost in Euro per cm square: ";
   cin>>perUnit;
   totalCost = area*perUnit + (area*perUnit*0.02);
  
   cout<<"TOtal Cost in Euro: "<<totalCost<<endl;
  

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote