- #1
7longhorn
- 5
- 0
Hi, could some one please verify that I successfully completed the objective of my programming homework? This is my first assignment and I'm just being extra cautious that I did everything right.
So the user provides measurements in inches but the program must then convert them into centimeters. Here is my code:
Thanks!
Assignment
A manufacturer wishes to determine the cost of producing an open-top cylindrical container. The surface area of the container is the sum of the area of the circular base plus the area of the outside (the circumference of the base times the height). Write a program to take the radius of the base, the height of the container, the cost per square centimeter of the material, and the number of containers to be produced. Calculate the cost of each container and the total cost of producing all the containers.
Instructor's Notes:
You must ask for the user to enter the radius and base measurements in INCHES.
So the user provides measurements in inches but the program must then convert them into centimeters. Here is my code:
Code:
#include <iostream>
using namespace std;
int main()
{
double radius;
double height;
double cost;
int nContainers;
double SA;
double costContainer;
double costAll;
float pi = 3.14159265;
cout << "Enter the radius of the base (in inches): ";
cin >> radius;
cout << "Enter the height of the container (in inches): ";
cin >> height;
cout << "Enter the cost of each container per square centimeter: $";
cin >> cost;
cout << "Enter the number of containers to be produced: ";
cin >> nContainers;
double Radius = radius * 2.54;
double Height = height * 2.54;
SA = pi * Radius * Radius + 2 * pi * Radius * Height;
costContainer = SA * cost;
costAll = costContainer * nContainers;
cout << nContainers << " container(s) at $" << cost << " per square centimeter will cost $" << costContainer << " each." << endl;
cout << "The grand total for " << nContainers << " containers is $" << costAll << "." << endl;
return 0;
}
Thanks!