Windchill is just not working..help me learn pls.

Hello thnks to those that responded to my previous posts.
I am making a windchill table. I have the basic setup right I believe. My main problem is the actual windchill in the table never changes. For instance a wind speed of 5 with a temp of 5 gives me a windchill of -4.6, but the whole table prints out -4.6. Here is my code HELP ME LEARN PLS! PS..Im a newb so give it to me gently.

#include <cstdlib>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <sstream>
#include <time.h>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{

string wSpd[]={"W","I","N","D"," ","S","P","E","E","D"};
int windSpeed = 5;
int windSpeedA = 5;
int Temp = 5;
int tempCount = -1;
int wSpdCount = 0;
double windChill;

windChill=35.74+0.6215*Temp-35.75*pow(windSpeed,0.16)
+0.4275*Temp*pow(windSpeed,0.16);

cout<<fixed<<setprecision(1)<<showpoint;
cout<<right<<setw(47)<<"TEMPERATURE"<<endl;
while(tempCount<=7)
{
if(tempCount<0)
{
cout<<" ";
}
cout<<Temp<<" ";
tempCount++;
Temp=Temp+5;
}
Temp = 5;
cout<<endl<<endl;

while(wSpdCount<10)
{
cout<<wSpd[wSpdCount]<<setw(5)<<windSpeedA;

for(tempCount=1;tempCount<10;tempCount++)
{
cout<<setw(7)<<windChill;
Temp=Temp+5;
windSpeed=windSpeed+5;
}
cout<<endl;
windSpeedA=windSpeedA+5;
wSpdCount++;
}

cout<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}

Also if someone could tell me how to round up my windchill that would be awsum.
You're only ever calculating the wind chill once. How do you expect it to ever be different?

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Last edited on
First, Please always use code tags - edit your post, select all the code, press the <> button on the right under the format menu. So it looks like this :

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
using namespace std;

i#include <cstdlib>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <sstream>
#include <time.h>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{

string wSpd[]={"W","I","N","D"," ","S","P","E","E","D"};
int windSpeed = 5;
int windSpeedA = 5;
int Temp = 5;
int tempCount = -1;
int wSpdCount = 0;
double windChill;


You only calculate Wind Chill once, then repeatedly print it out.

This is a lot of code for what it does - probably could do the whole thing in 10 lines. Consider this psuedo code :

1
2
3
// nested for loops that increments temp & wind speed
// calc the wind chill using a function call
// print the answer 


I think it would be a good idea for you to write psuedo code with comments, then go back and write the C++ code after the comments. It is an iterative process - start of with general ideas, then go back & fill in more detail. When ready, write the C++ code. This is a good way of organising your thoughts.

So some other things to help you out :

Why so many #includes ? Only put them in if you need them.

string WindSpeed = "WINDSPEED"; // I name gave the variable a better name

And what are you trying to do with it here?

1
2
3
while(wSpdCount<10)
{
cout<<wSpd[wSpdCount]<<setw(5)<<windSpeedA;


This code :

1
2
3
4
5
6
while(tempCount<=7)
{
if(tempCount<0)
{
cout<<" ";
}


prints 1 space - why are you deliberately being obscure?

This :
Temp=Temp+5;

can be written like this :

Temp += 5;

Some other ideas :

Consider using arrays to store the info into.

Hope all goes well.
Topic archived. No new replies allowed.