473,383 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Reading in two data files...but not getting an output....

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?

Expand|Select|Wrap|Line Numbers
  1.  # include<fstream.h> 
  2. # include<iostream.h>
  3. # include<stdio.h>
  4. # include<math.h>
  5. # include<stdlib.h>
  6.  
  7.  
  8. main()
  9. {
  10.     double alt[105],temp[105],rho[105],press[105],alt1[7],z,t,r,p;
  11.     int i,j,a,ie,n;
  12.     z=0;
  13.     FILE*fo;
  14.     fo=fopen("project4.dat","w");
  15.     fprintf(fo,"Atmospheric Conditions\n");
  16.     fprintf(fo,"--------------------------------------------------\n");
  17.     fprintf(fo,"Alt(ft)\tPress(lb/in^2)\tTemp(F)\tDensity(lb/in^3)\n");
  18.     fprintf(fo,"--------------------------------------------------\n\n");
  19.  
  20.     ifstream inf;
  21.     inf.open("atm7.txt",ios::in);
  22.     inf>>ie;
  23.     for(i=1; i<=ie; i++)
  24.     {
  25.     inf>>alt[i]>>temp[i]>>rho[i]>>press[i];
  26.     }
  27.     inf.close();
  28.  
  29.     for(j = 1; (j <=100000) && (alt[j]<=z); j++);
  30.     {
  31.     ifstream fin;
  32.     fin.open("altproject4.txt",ios::in);
  33.     fin>>n;
  34.     for(a=0; alt1[a]<=n; a++)
  35.     {
  36.     t= ((temp[j] +(z-alt1[a]))*(temp[j+1]-temp[j]))/(alt[j+1]-alt1[a]);
  37.     r= ((rho[j] +(z-alt1[a]))*(rho[j+1]-rho[j]))/(alt[j+1]-alt[i]);
  38.     p= ((press[j] +(z-alt1[a]))*(press[j+1]-press[j]))/(alt[j+1]-alt1[a]);
  39.     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);
  40.     }
  41.     fin.close();
  42.  
  43.     }
  44.  
  45. return 0;
  46.  
  47. }
  48.  
Oct 21 '06 #1
1 1890
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.
Oct 21 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: John | last post by:
I have over 5000 thumbnail pictures of size 5kb each. I would like to able to load all 5000 pictures and view 50 per page using mysql_data_seek(). I would like to know what are the advantages and...
3
by: Olivier Maurice | last post by:
Hi all, I suppose some of you know the program Redmon (type redmon in google, first result). This neat little tool allows to hook up any functionality to a printer by putting the file printed...
9
by: Yaro | last post by:
Hello DB2/NT 8.1.3 Sorry for stupid questions. I am newbe in DB2. 1. How can I read *.sql script (with table and function definitions) into a database? Tool, command... 2. In Project Center...
9
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
14
by: noridotjabi | last post by:
Two questions. 1)Is there any way that I can read from an executable and then execute what I have read. EXAMPLE: text text this is more text
5
by: jeff | last post by:
i stated using a python module called id3reader (http://www.nedbatchelder.com/code/modules/id3reader.html) and i tried to use it to organize all my music files (right now they are all in one...
10
by: Tyler | last post by:
Hello All: After trying to find an open source alternative to Matlab (or IDL), I am currently getting acquainted with Python and, in particular SciPy, NumPy, and Matplotlib. While I await the...
21
by: Naya | last post by:
Hello, everyone!!! Well, I have a situation here. I am trying to read this data from a file, but the wrong values keep spitting out at me. Here's what I mean: Program: int main() {...
2
by: Clive Green | last post by:
Hello peeps, I am using PHP 5.2.2 together with MP3_Id (a PEAR module for reading and writing MP3 tags). I have been using PHP on the command line (Mac OS X Unix shell, to be precise), and am...
13
by: swetha | last post by:
HI Every1, I have a problem in reading a binary file. Actually i want a C program which reads in the data from a file which is in binary format and i want to update values in it. The file...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.