Quote:
Originally Posted by techgeek.in
see this:-
Code:
//This program generates a table for the specific internal energy
//and the specific enthalpy of Methane from 300K to 1000K using the
//specific heat variations listed on Table A.21
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main(){
int QA;
float T1=300,T2,end1,inc;
double a=3.826,b=-3.979,c=24.558,d=-22.733,e=6.963;
double A,B,C,D,E,H,U,R=8.3143,M=16.04,i=10;
char error[128];
do{
do{
system("cls");
printf("Enter the Increment in Temperature: ");
scanf("%s",&error);
inc=atof(error);
if(inc<=0){
system("cls");
printf("Invalid Input. Please try again!!!\n");
printf("Please press the spacebar to continue!!");
getche();
}
}while(inc<=0);
T2=T1+inc;
end1=1000-inc;
printf("The increment is %.3f\n\n",inc);
printf("\nInitial Temperature\tFinal Temperature\tEnthalpy\tInternal Energy\n");
while(T1<=end1){
T1+=inc;
T2+=inc;
A=a*(T2-T1);
B=(1/pow(i,3))*(b/2)*(pow(T2,2)-pow(T1,2));
C=(1/pow(i,6))*(c/3)*(pow(T2,3)-pow(T1,3));
D=(1/pow(i,9))*(d/4)*(pow(T2,4)-pow(T1,4));
E=(1/pow(i,12))*(e/5)*(pow(T2,5)-pow(T1,5));
H=(R/M)*(A+B+C+D+E);
U=(R/M)*((A+B+C+D+E)-(T2-T1));
printf("%10.3f K\t\t%10.3f K\t\t%.3f kJ/kg\t%.3f kJ/kg\n",T1,T2,H,U);
}
do{//This used to ask the user if s/he wants to repeat the evaluation
printf("\n\nDo you want to repeat the computation or Quit?\n");
printf("[1] Yes\n");
printf("[2] Quit\n");
scanf("%s",&error);
QA=atoi(error);
switch(QA){
case 1:
break;
case 2://Return to the selection screen
exit(1);
break;
default://The program redirects invalid inputs to this part
system("cls");
printf("Invalid input. Please try again!!!\n");
printf("Please press the spacebar to continue!!");
getche();
break;
}
}while(QA>2||QA<1);
}while(QA==1 && T2<=1000);
getche();
}
correct the above code like this
Code:
.......................
switch(QA){
case 1:
T1=300;//add this
T2=0;//add this
break;
case 2://Return to the selection screen
exit(1);
......................
Code:
}while(QA>2||QA<1);
}while(QA==1 && T2<=1000); //i am not sure but i think you must remove =
getche();
}