What I'm trying to do:
1. Attempt to open the file. The filename, c:\\windData.tx t, should be hardcoded into your program. Note the two slash characters in the file name. If the file cannot be opened, display a message and exit the program.
2. From the file read a temperature and a wind speed. Both values should be stored in variables declared as double. The file is a text file.
3. Calculate the wind chill factor using a programmer written function, and display the result in the form:
For t = temperature from file
and v = wind speed from file
Wind chill index = calculated result degrees Fahrenheit.
4. Repeat these steps until an end of file is encountered.
What I have so far which isn't right i know ;) :
1. Attempt to open the file. The filename, c:\\windData.tx t, should be hardcoded into your program. Note the two slash characters in the file name. If the file cannot be opened, display a message and exit the program.
2. From the file read a temperature and a wind speed. Both values should be stored in variables declared as double. The file is a text file.
3. Calculate the wind chill factor using a programmer written function, and display the result in the form:
For t = temperature from file
and v = wind speed from file
Wind chill index = calculated result degrees Fahrenheit.
4. Repeat these steps until an end of file is encountered.
What I have so far which isn't right i know ;) :
Code:
#include <iostream> #include <fstream> #include <string> #include <math> using namespace std; double pow(double x, double y); double y = .16; int main( ) { // Open the file ifstream theFile("windData.txt"); cout << "Attempting to open the file" << endl; if (theFile.good( ) ) { double number = 0; double temp = 0; double windspd = 0; double count = 0; cout << "File opened successfully." << endl; while (theFile >> number) { if (count == 0) { temp = number; windspd = number; } double v = windspd; W = 35.74 + 0.6215(temp) - 35.75 pow(windspd, y) + 0.4275(temp)pow(windspd, y); //double W = (35.74 + 0.6215(t)) - 35.75 (pow(v, y)) + 0.4275(t)(pow(v, y)); cout << W << endl; temp += number; count++; } } else { cout << "\nCould not open the file..."; exit(1); } system("PAUSE"); cin.get(); return 0; }
Comment