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
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
usingnamespace 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;
}
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: