# Need some help with C programming

Tags:
• Programming
• Apps
Last response: in Apps General Discussion
Share
June 22, 2012 8:58:23 PM

Heres the code:

```#include <stdio.h>
void purpose(void);
double cost_of_each_container(double cost);
double total_cost_of_containers(double total);
int main(void)
{
double height;
double cps;
int containers;
double cpc;
double total;
purpose();
printf("\tEnter the radius of the base of the container in cm: ");
printf("\tEnter the height of the container in cm: ");
scanf("%lf", &height);
printf("\tEnter the cost per square centimeter: ");
scanf("%lf", &cps);
printf("\tEnter the number of containers: ");
scanf("%d", &containers);
printf("\n\t *****    OUTPUT  *****\n");
printf("\tHeight of the container %14.2lfcm\n\n", height);
printf("\tCost per square centimeter %11.2lf\n\n", cps);
printf("\tNumber of containers %17.2d\n\n", containers);
printf("\t*****    CALCULATED VALUES  *****\n\n");
cpc = cost_of_each_container(cost);
getch();
return 0;
}
void purpose(void)
{
printf("\n This program computes the cost per container and the total cost \n");
printf(" To use this program the user has to enter the radius, height, and cost per square \n");
printf(" from the keyboard and the program calculates the cost per container and total cost \n");
printf(" then prints out the radius, height, cost per square centimeter, number \n");
printf(" of containers, and the total\n\n\n");
}
double cost_of_each_container(double cost)
{
double cpc;
cpc = containers * cps;
return(cpc);
}```

I'm trying to call the function cost_of_each_container but its not working and i have no idea what i'm doing wrong please help. I know the spacing in the void purpose part is bad but i will fix that later. And if someone could tell me the math for the function cost_of_each_container because i know thats not right (i am trying to find the cost per container). Thanks!

June 22, 2012 9:29:39 PM

This is an assignment and I have to make three functions called purpose which i called and that one works fine. Then i have to make another called cost_of_each_container and one more called total_cost_of_containers. I can't figure out what i am doing wrong when trying to call these functions. Also these functions cannot have any input or output ops only arithmetic. Thanks!
m
0
l
Related resources
June 22, 2012 11:04:45 PM

m
0
l
a b L Programming
June 23, 2012 5:50:22 AM

I'm not experienced at all in C, but you appear to be passing calling cost_of_each_container an undeclared variable "cost". Surely your compiler would have picked up on this though.
m
0
l
a b L Programming
June 25, 2012 1:04:56 PM

+1 cost is missing.

So the math is fairly straightforward here you are trying to calculate the volume of a cylinder. So use:

volume = 3.14 * pow(radius,2) * height;

The cost of this volume is simply:

cost = cpc * volume;

Don't really understand the point of your cost_of_each_container function though when it's only taking a "cost" parameter. Really you want a definition like:

```double cost_of_each_container(double costPerCm, double height, double radius){
double volume = 3.14 * pow(radius,2) * height;
return volume * costPerCm;
}```
m
0
l
June 25, 2012 1:29:56 PM

Jordannn15 said:
Heres the code:

`#include <stdio.h> void purpose(void);double cost_of_each_container(double cost);double total_cost_of_containers(double total); int main(void){    double radius;    double height;    double cps;    int containers;    double cpc;    double total;     purpose();     printf("\tEnter the radius of the base of the container in cm: ");    scanf("%lf", &radius);    printf("\tEnter the height of the container in cm: ");    scanf("%lf", &height);    printf("\tEnter the cost per square centimeter: ");    scanf("%lf", &cps);    printf("\tEnter the number of containers: ");    scanf("%d", &containers);    printf("\n\t *****    OUTPUT  *****\n");    printf("\n\tRadius of the container %14.2lfcm\n\n", radius);    printf("\tHeight of the container %14.2lfcm\n\n", height);    printf("\tCost per square centimeter %11.2lf\n\n", cps);    printf("\tNumber of containers %17.2d\n\n", containers);    printf("\t*****    CALCULATED VALUES  *****\n\n");    cpc = cost_of_each_container(cost);     getch();    return 0;}     void purpose(void)    {         printf("\n This program computes the cost per container and the total cost \n");         printf(" To use this program the user has to enter the radius, height, and cost per square \n");         printf(" from the keyboard and the program calculates the cost per container and total cost \n");         printf(" then prints out the radius, height, cost per square centimeter, number \n");         printf(" of containers, and the total\n\n\n");    }     double cost_of_each_container(double cost)    {          double cpc;           cpc = containers * cps;           return(cpc);    }`

I'm trying to call the function cost_of_each_container but its not working and i have no idea what i'm doing wrong please help. I know the spacing in the void purpose part is bad but i will fix that later. And if someone could tell me the math for the function cost_of_each_container because i know thats not right (i am trying to find the cost per container). Thanks!

try this code, it will now work, you still need to calculate values

`#include<conio.h>#include <stdio.h>void purpose(void);double cost_of_each_container(int containers, double cps);double total_cost_of_containers(double total);int main(void){	 double cost;	 double radius;	 double height;	 double cps;	 int containers;	 double cpc;	 double total; 	 purpose(); 	 printf("\tEnter the radius of the base of the container in cm: " );	 scanf("%lf", &radius);	 printf("\tEnter the height of the container in cm: " );	 scanf("%lf", &height);	 printf("\tEnter the cost per square centimeter: " );	 scanf("%lf", &cps);	 printf("\tEnter the number of containers: " );	 scanf("%d", &containers);	 printf("\n\t *****    OUTPUT  *****\n" );	 printf("\n\tRadius of the container %14.2lfcm\n\n", radius);	 printf("\tHeight of the container %14.2lfcm\n\n", height);	 printf("\tCost per square centimeter %11.2lf\n\n", cps);	 printf("\tNumber of containers %17.2d\n\n", containers);	 printf("\t*****    CALCULATED VALUES  *****\n\n" );	 cpc = cost_of_each_container(containers,cost); 	 getch();	 return 0;}	 void purpose(void)	 {		  printf("\n This program computes the cost per container and the total cost \n" );		  printf(" To use this program the user has to enter the radius, height, and cost per square \n" );		  printf(" from the keyboard and the program calculates the cost per container and total cost \n" );		  printf(" then prints out the radius, height, cost per square centimeter, number \n" );		  printf(" of containers, and the total\n\n\n" );	 } 	 double cost_of_each_container(int containers, double cps)	 {			 double cpc; 			 cpc = containers * cps; 			 return(cpc);	 }`

its output is like this
m
0
l
!