input/output files please help

I have to write a program that reads in a large amount of data (7 columns) and then calculates the virtual temp for each data line using three data points (columns- pressure, temp, and dewpoint). Then I modify the program to calculate the estimates of the height of the sounding. I have most of the code done but keep get a warning: âtempâ is used uninitialized in this function. I don't know where I went wrong. I need 120 outputs and only get 1 when I compile.
virtual temperature = -0
height = 0

thank you in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 #include <iostream> 
#include <fstream> 
#include <cstdlib>
#include <math.h> 
using namespace std;
int main () 
{ 

   ifstream inputfile;
   ofstream outputfile; 
   
char filein[16], fileout[16];
double level, hght, temp, dwpt, omeg, virtemp, z;
 
cout<<"enter file for input"<<endl; 
//prompts the user to enter the input filename 
cin>>filein; 
cout<<"enter file for output"<<endl; 
//prompts the user to enter the output filename 
cin>>fileout; 

inputfile.open(filein); //opens the inputfile 

virtemp=(temp+273.15)/(1-0.379*((6.11*pow(10,((7.5*dwpt)/(237.7+dwpt))/level)))); 

cout<<" virtual temperature = "<<virtemp<<endl; 

z=((287/9.8)*(virtemp)*(omeg/level))+hght; 

cout<< "height = "<<z<<endl; 


inputfile.close(); //closes input file
outputfile.close();//closes output file
return 0; 
} 
 
Last edited on
You never read any data in from your file which I believe you meant to store in the all the variables you declared, so when you go to plug those variables into your formula, you're plugging in garbage because you've declared the variables, but they have not been given a value and remain uninitialized. I don't know how you're file is set up, but if its just numbers separated by spaces, you'd read in data after opening it like such:

inputfile >> level >> hght >> tempt >> dwpt >> omeg;

But again, it depends of the format of the file.
Topic archived. No new replies allowed.