Reputation: 17
I am having an issue on how I would construct my length height and width to calculate in Cubic feet. I have already calculated it in Cubic inches, I was just confused on how to set it up without using any conditionals and just use data types and mixed data types allowed. I am just having an issue structuring the code to show up and calculate right, but I am kind of lost on how to do that in code. I tried, so here is the code:
#include <stdio.h>
#include <stdlib.h>
int main() {
//Initialized variables of Length, height, and width of a box.
double length_of_box, height_of_box, width_of_box;
double cubicInches_of_box, cubicFeet_of_box;
//prompt and read the size of box to the user for them to enter in length, height, and width.
printf("What is the size of your box in length, height, and width in inches?\n");
scanf("%lf", &length_of_box);
scanf("%lf", &height_of_box);
scanf("%lf", &width_of_box);
printf("Your box\'s Dimension\'s\n length: %.1lf\n Height: %.2lf\n Width: %.3lf\n ", length_of_box, height_of_box, width_of_box);
//Calculates volume of box in cubic inches.
cubicInches_of_box = length_of_box*height_of_box*width_of_box;
printf("The volume of your box: %.2lf cubic inches.\n", cubicInches_of_box);
//Calculates volume of box in cubic feet.
cubicFeet_of_box = cubicInches_of_box/2;
printf("The volume of your box: %.2lf cubic feet.\n",cubicFeet_of_box);
system("pause");
return 0;
}
Upvotes: 0
Views: 1272
Reputation: 1060
Your calculation
cubicFeet_of_box = cubicInches_of_box/2;
should be
cubicFeet_of_box = cubicInches_of_box/1728; // 12*12*12
What other problems are you having?
Upvotes: 1
Reputation: 223917
Your conversion factor is wrong. The number of cubic feet is not half the number of cubic inches. The proper conversion:
1 cubic foot = 1 ft * 1 ft * 1 ft = 12 in * 12 in * 12 in = 1728 cubic inches
So you need to divide cubic inches by 1728 to get cubic feet.
Upvotes: 3