Code:
#include <stdio.h>
void enter_temp(float*, float*);
void convert(float*, float*);
void cop(float*, float*,float*, float*);
int main(void){
float h, c, hcop, ccop;
int again=1;
int selection;
float kelvin;
printf("Select your computation, 1 for heat pump or 2 for refrigerator:");
scanf("%d", &selection);
while (again==1){
printf("Continue?? <type 1 to continue>.");
scanf("%d", &again);
}
while(selection !=1 && selection !=2){
printf("Select your computation, 1 for heat pump or 2 for refrigerator:");
scanf("%d", &selection);}
enter_temp(&h, &c);
printf("Enter the temperatures for hot and cold reservoirs.\n");
printf("%f%f", &h, &c);
printf("Temperatures must be greater than -273.15 and hot reservoir");
printf("temperatures must be greater than cold reservoir temperature.");
convert(&h, &c);
printf("Temp = %f, &c (cold) and %f, &h (hot) in Celsius\n");
printf("Temp = %f, (cold) and %f (hot) in Kelvin\n", c+273.15, h+273.15);
scanf("%.2f%.2f", &kelvin);
cop(&h, &c, &hcop, &ccop);
printf ("The value of cop for refrigerator cycle = %f\n", ccop);
scanf("%.2f", &ccop);
printf("The value of cop for heat pump = %f\n", hcop);
scanf("%.2f", &hcop);
printf("Continue?? <type 1 to continue.");
scanf("%d", &again);
return 0;
}
void enter_temp(float *hPtr, float *cPtr){
float h, c;
printf("Enter the temperatures for hot and cold reservoirs.\n");
printf("%f%f", &h, &c);
printf("Temperatures must be greater than -273.15 and hot reservoir");
printf("temperatures must be greater than cold reservoir temperature.");
while (h > -273.15 && c > -273.15){
printf("Enter the temperatures for hot and cold reservoirs.\n");
printf("%f%f", &h, &c);
printf("Temperatures must be greater than -273.15 and hot reservoir");
printf("temperatures must be greater than cold reservoir temperature.");
}
while (h>c){
printf("Enter the temperatures for hot and cold reservoirs.");
printf("%f%f", &h, &c);
printf("Temperatures must be greater than -273.15 and hot reservoir");
printf("temperatures must be greater than cold reservoir temperature.");}
return;
}
void convert(float *hptr, float *cptr){
float h, c, kelvin;
kelvin = h + 273.15;
kelvin = c + 273.15;
printf("Temp = %f, &c (cold) and %f, &h (hot) in Celsius\n");
printf("Temp = %f, (cold) and %f (hot) in Kelvin\n", c+273.15, h+273.15);
scanf("%.2f%.2f", &kelvin);
return;
}
void cop(float *hPtr,float *cPtr,float *hcopPtr,float *ccopPtr){
float h, c, hcop, ccop;
ccop= c/ h-c;
hcop= h/ h-c;
printf ("The value of cop for refrigerator cycle = %f\n", ccop);
scanf("%.2f", &ccop);
printf("The value of cop for heat pump = %f\n", hcop);
scanf("%.2f", &hcop);
return;
}