Need some help with C programming

Jordannn15

Honorable
Jun 2, 2012
17
0
10,560
Heres the code:

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!
 

Jordannn15

Honorable
Jun 2, 2012
17
0
10,560
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!
 

Rusting In Peace

Distinguished
Jul 2, 2009
312
0
19,060
+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:

Code:
double cost_of_each_container(double costPerCm, double height, double radius){
	double volume = 3.14 * pow(radius,2) * height;
        return volume * costPerCm;
}
 

truegenius

Distinguished
Oct 22, 2011
113
0
18,660



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

Code:
#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
Capture-3.jpg