This program is supposed to read in a text file with values of altitudes ranging from 0-100,000 increasing by 1000, with these altitude values there are corresponding pressure, temperature, and density values. The program also has to read in another text file with the following altitude values 8250,15360,34840,55685,72470,94522. The purpose of the program is to use the first text file to produce pressure, temperature, and density values for the altitudes of the second text file. I wrote the program and it is giving me an output but no numerical values for z, p, t, and r. Can someone take a look at it? - # include<fstream.h>
-
# include<iostream.h>
-
# include<stdio.h>
-
# include<math.h>
-
# include<stdlib.h>
-
-
-
main()
-
{
-
double alt[105],temp[105],rho[105],press[105],alt1[7],z,t,r,p;
-
int i,j,a,ie,n;
-
z=0;
-
FILE*fo;
-
fo=fopen("project4.dat","w");
-
fprintf(fo,"Atmospheric Conditions\n");
-
fprintf(fo,"--------------------------------------------------\n");
-
fprintf(fo,"Alt(ft)\tPress(lb/in^2)\tTemp(F)\tDensity(lb/in^3)\n");
-
fprintf(fo,"--------------------------------------------------\n\n");
-
-
ifstream inf;
-
inf.open("atm7.txt",ios::in);
-
inf>>ie;
-
for(i=1; i<=ie; i++)
-
{
-
inf>>alt[i]>>temp[i]>>rho[i]>>press[i];
-
}
-
inf.close();
-
-
for(j = 1; (j <=100000) && (alt[j]<=z); j++);
-
{
-
ifstream fin;
-
fin.open("altproject4.txt",ios::in);
-
fin>>n;
-
for(a=0; alt1[a]<=n; a++)
-
{
-
t= ((temp[j] +(z-alt1[a]))*(temp[j+1]-temp[j]))/(alt[j+1]-alt1[a]);
-
r= ((rho[j] +(z-alt1[a]))*(rho[j+1]-rho[j]))/(alt[j+1]-alt[i]);
-
p= ((press[j] +(z-alt1[a]))*(press[j+1]-press[j]))/(alt[j+1]-alt1[a]);
-
fprintf(fo,"z=%6.0f ft\t\tt=%7.2f F\t\tr=%8.5f lb/in^3\t\tp=%8.5flb/^in2\n",z,t,r,p);
-
}
-
fin.close();
-
-
}
-
-
return 0;
-
-
}
-
1 1746 arne 315
Expert 100+
This program is supposed to read in a text file with values of altitudes ranging from 0-100,000 increasing by 1000, with these altitude values there are corresponding pressure, temperature, and density values. The program also has to read in another text file with the following altitude values 8250,15360,34840,55685,72470,94522. The purpose of the program is to use the first text file to produce pressure, temperature, and density values for the altitudes of the second text file. I wrote the program and it is giving me an output but no numerical values for z, p, t, and r. Can someone take a look at it?
# include<fstream.h>
# include<iostream.h>
# include<stdio.h>
# include<math.h>
# include<stdlib.h>
main()
{
double alt[105],temp[105],rho[105],press[105],alt1[7],z,t,r,p;
int i,j,a,ie,n;
z=0;
FILE*fo;
fo=fopen("project4.dat","w");
fprintf(fo,"Atmospheric Conditions\n");
fprintf(fo,"--------------------------------------------------\n");
fprintf(fo,"Alt(ft)\tPress(lb/in^2)\tTemp(F)\tDensity(lb/in^3)\n");
fprintf(fo,"--------------------------------------------------\n\n");
ifstream inf;
inf.open("atm7.txt",ios::in);
inf>>ie;
for(i=1; i<=ie; i++)
{
inf>>alt[i]>>temp[i]>>rho[i]>>press[i];
}
inf.close();
for(j = 1; (j <=100000) && (alt[j]<=z); j++);
{
ifstream fin;
fin.open("altproject4.txt",ios::in);
fin>>n;
for(a=0; alt1[a]<=n; a++)
{
t= ((temp[j] +(z-alt1[a]))*(temp[j+1]-temp[j]))/(alt[j+1]-alt1[a]);
r= ((rho[j] +(z-alt1[a]))*(rho[j+1]-rho[j]))/(alt[j+1]-alt[i]);
p= ((press[j] +(z-alt1[a]))*(press[j+1]-press[j]))/(alt[j+1]-alt1[a]);
fprintf(fo,"z=%6.0f ft\t\tt=%7.2f F\t\tr=%8.5f lb/in^3\t\tp=%8.5flb/^in2\n",z,t,r,p);
}
fin.close();
}
return 0;
}
By non-numerical values you something like nan, inf, -inf and the like?
Check (print out) the values you are using for the calculation of t, r, and p, i.e. temp[j], alt1[a] and the like. You may divide by zero, which yields an undefined result in the case of floating point arithmetic.
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
7 posts
views
Thread by John |
last post: by
|
3 posts
views
Thread by Olivier Maurice |
last post: by
|
9 posts
views
Thread by Yaro |
last post: by
|
9 posts
views
Thread by jeff M via .NET 247 |
last post: by
|
14 posts
views
Thread by noridotjabi |
last post: by
|
5 posts
views
Thread by jeff |
last post: by
|
10 posts
views
Thread by Tyler |
last post: by
|
21 posts
views
Thread by Naya |
last post: by
|
2 posts
views
Thread by Clive Green |
last post: by
|
13 posts
views
Thread by swetha |
last post: by
| | | | | | | | | | |