469,929 Members | 1,569 Online

# Need help using pow function in problem

What I'm trying to do:

1. Attempt to open the file. The filename, c:\\windData.txt, 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 ;) :
Expand|Select|Wrap|Line Numbers
1.
2. #include <iostream>
3. #include <fstream>
4. #include <string>
5. #include [itex]
6.
7. using namespace std;
8. double pow(double x, double y);
9. double y = .16;
10. int main( )
11. {
12.
13.
14.    // Open the file
15.    ifstream theFile("windData.txt");
16.        cout << "Attempting to open the file" << endl;
17.
18.    if (theFile.good( ) )
19.    {
20.        double number = 0;
21.        double temp = 0;
22.        double windspd = 0;
23.        double count = 0;
24.
25.        cout << "File opened successfully." << endl;
26.        while (theFile >> number)
27.        {
28.            if (count == 0)
29.            {
30.                temp = number;
31.                windspd = number;
32.            }
33.
34.
35.
36.              double v = windspd;
37.             W = 35.74 + 0.6215(temp) - 35.75 pow(windspd, y) + 0.4275(temp)pow(windspd, y);
38.              //double W = (35.74 + 0.6215(t)) - 35.75 (pow(v, y)) + 0.4275(t)(pow(v, y));
39.         cout << W << endl;
40.
41.
42.         temp += number;
43.         count++;
44.
45.         }
46.
47.    }
48.    else
49.    {
50.        cout << "\nCould not open the file...";
51.        exit(1);
52.    }
53.
54.    system("PAUSE");
55.    cin.get();
56.    return 0;
57. }
58.
Oct 26 '06 #1
2 3053
The actual formula is :

W = 35.74 + 0.6215t - 35.75 (v0.16) + 0.4275t(v0.16)
Oct 26 '06 #2
Banfa
9,065 Expert Mod 8TB
I see nothing wrong in the way you are using the pow function but in this line

W = 35.74 + 0.6215(temp) - 35.75 pow(windspd, y) + 0.4275(temp)pow(windspd, y);

You need to add all the multiplication operators, i.e. 0.6215(temp) needs to be 0.6215 * temp
Oct 26 '06 #3