You are viewing our Forum Archives. To view or take place in current topics click here.
Need some help with C programming! +rep for whoever helps me
Posted:

Need some help with C programming! +rep for whoever helps mePosted:

Jordannn23
  • Challenger
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7


#include <stdio.h>
#define PI 3.14

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;
    double cpc;
    double c;
    int containers;
    double total;
    double tc;
   
    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");
    printf("\tCost per container         $%10.2lf\n\n", cpc);
    printf("\tTotal cost                 $%10.2lf\n\n", tc);
   
    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 \n");
         printf(" cost per square from the keyboard and the program calculates the cost \n");
         printf(" per container and total cost then prints out the radius, height, \n");
         printf(" cost per square centimeter, number of containers, and the total.\n\n\n");
    }
   
    double cost_of_each_container(double cost)
    {
            double radius;
            double height;
            double cpc;
            cpc = (pow(3.25, 2.0) * PI) * height;
            return(cpc);
    }
   
    double total_cost_of_containers(double total)   
    {
           double tc;
           double cpc;
           int containers;
           tc = cpc * containers;
           return(tc);
    }


Okay I have called my first function which is obviously purpose, next I have no idea how to call my other two functions which are double cost_of_each_container and double total_cost_of_containers. Please someone help me call these functions. Thanks!
#2. Posted:
Jordannn23
  • Challenger
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Someone please help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#3. Posted:
Experiment5X
  • TTG Senior
Status: Offline
Joined: Aug 14, 200915Year Member
Posts: 1,291
Reputation Power: 65
Status: Offline
Joined: Aug 14, 200915Year Member
Posts: 1,291
Reputation Power: 65
The first function that you called, purpose didn't have any parameters meaning that you didn't need to give the function any values in order to do it's thing. The other 2 functions do have parameters so you need to pass them values in order for them to run. So to call them you need to give them values so, you'd have to do something like this:


cpc = cost_of_each_container(cps);


Here when we call the function we give it the cost per square centimeter so that it can calculate the cost of each container. It "returns" that calculated value back to us, and it is stored in the cpc variable.

Let's see if you can figure out how to call the other function, it'll be good practice.
#4. Posted:
Jordannn23
  • Challenger
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Okay and would the other one be:
 
tc = total_cost_of_containers(total);

?
#5. Posted:
TTGXMODsX
  • TTG Natural
Status: Offline
Joined: Feb 06, 201014Year Member
Posts: 996
Reputation Power: 64
Status: Offline
Joined: Feb 06, 201014Year Member
Posts: 996
Reputation Power: 64
Jordannn23 wrote Okay and would the other one be:
 
tc = total_cost_of_containers(total);

?


You got the idea mate
#6. Posted:
Jordannn23
  • Challenger
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Status: Offline
Joined: Jun 22, 201113Year Member
Posts: 199
Reputation Power: 7
Okay now another question if i have the radius as 3.25cm, height as 12.50cm, cost per square cm as 0.05, number of containers as 60 what is the formula or what would I have to add/subtract/multiply or divide to get the cost per container which is on this sample output which is where I also got the other numbers my cost per containers with those numbers is 14.42 what do I have to put together to get that?
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.