Code:
/* This program is used to solve simple conduction problems using various forms of the formula*/
#include <stdio.h> /* define printf and scanf */
#include <math.h> /* define mathematical operations */
double calc_h (double coef, double thickness, double area, double temp1, double temp2) ; /* define function named calc_k */
double calc_k (double heat_rate, double thickness, double area, double temp1, double temp2) ; /* define function named calc_k */
double calc_a (double heat_rate, double thickness, double coef, double temp1, double temp2) ; /* define function named calc_a */
double calc_x (double heat_rate, double coef, double area, double temp1, double temp2) ; /* define function named calc_x */
double calc_t2 (double heat_rate, double thickness, double area, double temp1, double coef) ; /* define function named calc_t1 */
double calc_t1 (double heat_rate, double thickness, double area, double coef, double temp2) ; /* define function named calc_t2 */
void check (double var, double *temporary) ;
main()
{
/* define variables that will be used */
double heat_rate ;
double coef ;
double area ;
double temp1 ;
double temp2 ;
double thickness ;
double counter ;
counter = 1 ;
/* mention the background and the purpose of the program */
printf ("Respond to the the prompts with the data known, \n") ;
printf ("Unknown quantity, enter a question mark (?). \n") ;
printf ("Rate of heat transfer (unit = watts) ---> ") ;
scanf ("%lf",&heat_rate) ;
check (heat_rate, &counter) ;
printf ("Coefficient of thermal conductivity (unit = W/m-K) ---> ") ;
scanf ("%lf",&coef) ;
check (coef, &counter) ;
printf ("Cross sectional area of conductor (unit = m^2) ---> ") ;
scanf ("%lf",&area) ;
check (area, &counter) ;
printf ("Temperature on the first side (unit = Kelvin) ---> ") ;
scanf ("%lf",&temp1) ;
check (temp1, &counter) ;
printf ("Temperature on the second side (unit = Kelvin) ---> ") ;
scanf ("%lf",&temp2) ;
check (temp2, &counter) ;
printf ("Thickness of conductor (unit = m) ---> ") ;
scanf ("%lf",&thickness) ;
check (thickness, &counter) ;
if (counter == 0)
{
if(heat_rate == 0)
{
calc_h (coef, thickness, area, temp1, temp2) ;
}
else if (coef == 0)
{
calc_k (heat_rate, thickness, area, temp1, temp2) ;
}
else if (area == 0)
{
calc_a (heat_rate, thickness, coef, temp1, temp2) ;
}
else if (temp1 == 0)
{
calc_t1 (heat_rate, thickness, area, coef, temp2) ;
}
else if (temp2 == 0)
{
calc_t2 (heat_rate, thickness, area, temp1, coef) ;
}
else
{
calc_x (heat_rate, coef, area, temp1, temp2) ;
}
}else
{
printf ("Invalid input! You must input a question mark for the unknown variable. \n") ;
}
printf (" kA (T2-T1) \n") ;
printf (" H = ------------ \n") ;
printf (" x \n") ;
printf ("H = %lf W T2 = %lf K \n" ,heat_rate, temp2) ;
printf ("k = %lf W/m-K T1 = %lf K \n", coef, temp1) ;
printf ("A = %lf m^2 x = %lf m \n" , area, thickness) ;
system ("PAUSE") ;
return 0 ;
}
/* function named calc_k, used to calculate the coefficient of thermal conductivity */
double calc_k (double heat_rate, double thickness, double area, double temp1, double temp2)
{
return ((heat_rate*thickness)/(area*(temp2-temp1))) ;
}
/* function named calc_a, used to calculate the cross sectional area */
double calc_a (double heat_rate, double thickness, double coef, double temp1, double temp2)
{
return ((heat_rate*thickness)/(coef*(temp2-temp1))) ;
}
/* function named calc_x, used to calculate the thickness of the conductor */
double calc_x (double heat_rate, double coef, double area, double temp1, double temp2)
{
return ((coef*area*(temp2-temp1))/heat_rate) ;
}
/* function named calc_h, used to calculate the rate of heat transfer */
double calc_h (double coef, double thickness, double area, double temp1, double temp2)
{
return ((coef*area*(temp2-temp1))/thickness) ;
}
/* function named calc_t2, used to calculate the temperature on the second or furthest side of the conductor */
double calc_t2 (double heat_rate, double thickness, double area, double temp1, double coef)
{
return (((heat_rate*thickness)/(coef*area))+temp1) ;
}
/* function named calc_t1, used to calculate the temperature on the first or nearest side of the conductor */
double calc_t1 (double heat_rate, double thickness, double area, double coef, double temp2)
{
return (temp2-((heat_rate*thickness)/(coef*area))) ;
}
void check (double var, double *temporary)
{
if (var == 0)
*temporary = *temporary - 1 ;
else
printf ("\n") ;
}
could anyone help me with this? thank you so much again!