# Thread: help getting program to work

1. ## help getting program to work

I need help getting my progrm to work. I don't know how to do the functions and pointers. Any help would be greatly appreciated!

PROBLEM STATEMENT:

Cool it.

Refrigerators and heat pumps are modeled thermodynamically as reversible (i.e., no frictional effect) cycles that convert work energy to heating or cooling energy. For such cycles, we have a measure of efficiency, the coefficient of performance (cop), that is the ratio of cooling or heating divided by the work input required. The values of cop are as follows:

Refrigerator cycle: cop = Tc / Th - Tc

Heat pump: cop = Th / Th - Tc

where Tc and Th are the absolute temperatures (K) of cold and hot reservoirs.

Implementation Details:

Write a function to enter and return the temperatures of the cold and hot reservoirs in degrees Celsius; return them through pointer parameters. Make sure that both are greater than absolute 0(allow the user to correct any errors) and that they have the proper relationship to one another; that is Th > Tc (if not, swap them).
Write a function to convert a Celsius temperature to an absolute temperature in degrees Kelvin. Absolute 0 is -273.15 degrees Celsius.
Write a function, name cop(), that will compute both values of cop, given the Th and Tc, and return the results using call by address.
Write a main program that will calculate and print the values of cop for either a refrigerator or a heat pump. Use a query loop to repeat the process, asking the user to select one or the other computation or "quit". Do the input and calculations using functions described above. Although the cop() function returns two results, print only the result that the user requested.

Hint:

Kelvin = Celsius + 273.15;

Select your computation, 1 for heat pump or 2 for refrigerator :1

Enter temperatures for hot and cold reservoirs.

Temperatures must be greater than -273.15 and

hot reservoir temperature must be greater

than cold reservoir temperature.

56 78

Temp = 56.00 (cold) and 78.00 (hot) in Celsius

Temp = 329.15 (cold) and 351.15 (hot) in Kelvin

The value of cop for heat pump = 15.96

Continue ?? < type 1 to continue. 1

Select your computation, 1 for heat pump or 2 for refrigerator :1

Enter temperatures for hot and cold reservoirs.

Temperatures must be greater than -273.15 and

hot reservoir temperature must be greater

than cold reservoir temperature.

56 90

Temp = 56.00 (cold) and 90.00 (hot) in Celsius

Temp = 329.15 (cold) and 363.15 (hot) in Kelvin

The value of cop for heat pump = 10.68

Continue ?? < type 1 to continue. 1

Here's what I have:
Code:
```#include <stdio.h>

void enter_temp(float*, float*);
void convert (float*, float*);
void cop (float*, float*, float*, float*);

int main (void){

int selection;
int again = 1;

printf ("Select your computation, 1 for heat or 2 for refrigerator.");
scanf("%d", &selection);
printf ("Continue?? type 1 to continue");

while (selection !=1 && selection !=2) {
printf ("Select your computation, 1 for heat or 2 for refrigerator.");
scanf("%d", &selection);}

while (again == 1 ) {
printf ("Continue?? type 1 to %d", again);
scanf("%d", &again);
}
return 0;
}

void enter_temp(&h, &c)

{

printf ("Enter temperatures for hot and cold reservoirs.\n");
scanf("%lf%lf", &h, &c);

printf("Temperature must be greater than -273.15 and hot reservoir temperature must be greater than cold reservoir temperature.");

while (temperature > -273.15 && h > c) {
printf ("Enter temperatures for hot and cold reservoirs.\n");
scanf("%lf%lf", &h&c);
}

}

void convert(&h, &c)

{

printf("Temperature in Celsius = %lf (cold) and %lf (hot) in Celsius", h, c);

kelvin = celsius + 273.15;

printf ("Temperature = %lf, kelvin  (cold) and %lf, kelvin  (hot) in Celsius", h, c);
scanf("%lf", &kelvin);

}

void cop (&h, &c , &hcop, &ccop){

ccop = c / h - c; //refrigerator cycle

hcop = h / h - c;  //heat pump

if (cop = c / h - c)
printf (" The value of cop for refrigerator = %lf", ccop);
scanf("%lf", &ccop);
else
printf ("The value of cop for heat pump = %lf", hcop);
scanf ("%lf", &hcop);
}```
&#91;code]&#91;/code]tagged by Salem

2. First of all use code tags ..secound well you dont know how to use function ????? Read Read Read

3. Yes, please use code tags.

well... for starters

Code:
`void enter_temp(&h, &c)`
this is not how you defined a function header with pointers.

Also, where are you calling your functions???

Major help here

Why don't you try to find a book the has functions and pointers or ask your instructor.

Popular pages Recent additions