I am coding this using C. I am trying to get the pow function to work on this problem. using the base as the variable that the user would input. This program asks the user to calculate the area, and costs of a simple open can. here is the code:
//Pre-processor Directives
#include <stdio.h>
#include <math.h>
#define PI 3.14159
//Start of function
int main(void)
{
//Declared variables
float base_area, height_area, total_area_per_container;
float radius, height, cost_per_container, total_cost, cost_per_sq_cm;
int containers;
//user input
//radius input
printf("Enter radius of base in cm: ");
scanf("%f", &radius);
//height input
printf ("Enter height of container in cm: ");
scanf("%f", &height);
//material cost
printf("Enter material cost per square cm: ");
scanf(" $%f", &cost_per_sq_cm);
//amount of containers
printf("Enter the number of containers to be produced: ");
scanf("%d", &containers);
//calcualtions of each container
base_area = PI * pow(radius,2);
height_area = 2 * PI * radius * height;
total_area_per_container = base_area + height_area;
//calculation of the cost of the material
cost_per_container = total_area_per_container * cost_per_sq_cm;
total_cost = containers * cost_per_container;
//Print results
printf("Surface area of container: %.2f cm\n", total_area_per_container);
printf("Cost per container: $%.2f\n", cost_per_container);
printf("Total production costs: $%.2f\n", total_cost);
//exit program
return (0);
}
everything works fine if i take out the pow(radius,2) under the comment calculations of each container and put in "radius * radius" I just wanted to test to see how the pow function works. I feel like I am doing something wrong. Also I am using NetBeans IDE 8.0.2 to write the code.
Update1: using the gcc compiler that my instructor has. compiling my code on his computer gives me this faling response:
1st part is a bunch of jargin saying i am copying my code to his computer what follows is below- the directories my stuff is stored on was removed
In function `main':
undefined reference to `pow'
collect2: error: ld returned 1 exit status
gmake[2]: *** [dist/Debug/GNU-Linux-x86/hw5] Error 1
gmake[2]: Leaving directory
gmake[1]: *** [.build-conf] Error 2
gmake[1]: Leaving directory
gmake: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)