469,929 Members | 1,569 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

Need help using pow function in problem

9
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 <math>
  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
matrim
9
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

Post your reply

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

Similar topics

2 posts views Thread by lawrence | last post: by
5 posts views Thread by Sinan Nalkaya | last post: by
21 posts views Thread by Johan Tibell | last post: by
9 posts views Thread by pic078 via AccessMonster.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.