Wind Speed Flight Simulator Assignment Help.

Hi guys, a beginner here.
I'm supposed to make a program by midnight and I am stuck on this one part. Basically, I need to,
"Generate a table that contains 1 hour of simulated wind speeds and each line should contain the time in seconds and the corresponding wind speed. The time should start with 0 seconds. The increment in time should be 10 seconds and the final line of the table should correspond to 3600 seconds. The user should be prompted to enter the range of values of the gusts. The flight simulator wind table should also include a 0.5% possibility of encountering a small storm at each time step. When a storm is encountered , the average wind speed is increased by 10 mph for a period of 5 minutes. Denote storm in table with an *. Use at least two non void programmer defined functions.

Wind speed for a particular region can be modeled by using an average value and a range of gust values. The gust values are added to the average. For example, the wind speed might be 10 miles an hour, with added noise (which represents gusts) that range from 22 miles per hour to 2 miles per hour.

I got the wind speeds generated, but the only problem is that I just don't know how I can do the "storm encountered" part, and by that I mean I don't know how to assign the asteriks to the wind speeds for a specific range of time. Here is my program that i wrote.

Thanks for any advice.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  #include <iostream>
using namespace std;
double rand_float(double, double);
double rand_float_prob(double, double);
int main ()
{
    double wind_speed, wind_speed_storm, maxgust, mingust, avg_windspeed, min_prob, max_prob, probability, max_avgwindspeed, min_avgwindspeed;
    int time, stormtime;
    char repeat='y';
    cout << "Welcome to the Flight Simulator Wind Speed calculator.\n";

while (repeat=='y')
{
    cout << "Enter the value for the average wind speed: ";
    cin >> avg_windspeed;
    cout << "Enter the value for the minimum gust: ";
    cin >> mingust;
    cout << "Enter the value for the maximum gust (it must be greater than the minimum gust): ";
    cin >> maxgust;
    cout << "TIME   |    " << "WINDSPEED\n";
    cout << "--------------------------\n";


for (time=0; time<=3600; time+=10)
    {
    wind_speed=rand_float (min_avgwindspeed, max_avgwindspeed);
    probability = rand_float_prob(min_prob, max_prob); // probability is computed by inputting the constant minimum probability (0) and maximum probability (1)
    wind_speed_storm=wind_speed+10;
    min_avgwindspeed = avg_windspeed+mingust;
    max_avgwindspeed = avg_windspeed+maxgust;
    min_prob=0;
    max_prob=1;
    
    cout << time << "        " << wind_speed << endl;
    }
if (probability >=0.5)
{
    for (stormtime=time; stormtime<=300; stormtime+=10)
    {
        cout << stormtime << "       " << wind_speed_storm  << "*" << endl;
    }
}
    
    cout << "Would you like to continue with different values? If yes, press y or press any other key to exit otherwise.\n";
    cin >> repeat;

}
return 0;
}


double  rand_float(double min_avgwindspeed, double max_avgwindspeed)
{
    double wind_speed;
    wind_speed = ((double)rand()/RAND_MAX) * (max_avgwindspeed-min_avgwindspeed) + min_avgwindspeed;
    return wind_speed;
}

double rand_float_prob(double min_prob, double max_prob)
{
    double probability;
    probability= ((double)rand()/RAND_MAX) * (max_prob-min_prob) + min_prob;
    return probability;
}
I'd implement a separate storm value which would hold the end time of the storm, or 0 when there is no storm.

when you detect a storm starting "if( probability >0.5 )" calculate the end time and store it in the new variable.

when generating the wind speeds, you can use this new variable as a bool to determine if 10 needs to be added to the generated wind speed, and also if you need to add an '*' to the output.

remember to decrement the storm time if it's > 0 as you continue through the loop.

here's a sloppy non-working quick code/pseudo-code example of the modification
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
		for (time=0; time<=3600; time+=10)
		{
			wind_speed=rand_float (min_avgwindspeed, max_avgwindspeed);
			probability = rand_float_prob(min_prob, max_prob); // probability is computed by inputting the constant minimum probability (0) and maximum probability (1)
			if (probability >=0.5)
			{
				stormtime = // calculate end time of storm (current + 5min)
			{
			if( stormtime )
				wind_speed+=10;
			min_avgwindspeed = avg_windspeed+mingust;
			max_avgwindspeed = avg_windspeed+maxgust;
			min_prob=0;
			max_prob=1;
    
			if( stormtime )
			{
				cout << time << "        " << wind_speed << " *" << endl;
				stormtime -= 10;
			}
			else
				cout << time << "        " << wind_speed << endl;

		}
  
Last edited on
Hi Esslercuffi, thanks for responding.

I'm having trouble figuring out how to exactly figure out the current time. How am I supposed to know when the storm will be encountered when the probabilities are generated randomly?

Thanks.

Regards,
shindosu
well your time is counting in seconds, so 300 seconds = 5 minutes. Current time is the time in the 'for' loop. so stormtime = time+300; will give you the end time of the storm.

Also, your probability check should probably be <= 0.5, rather than >=0.5.
Last edited on
Hi Esslercuff,

I re-edited the code as told, however now I just keep getting asteriks next to every single velocities, with 10 mph added. Here's how it looks now.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  /*
This program will allow you to generate wind speeds between specific average wind speed values. Users will be prompted for the average wind speed, minimum and maximum windspeeds, and the program will automatically
display a table that shows the values between the maximum and minimum average windspeeds (+gust). There will be an asterik displayed for 300 seconds next to the values if a storm is encountered.
Date: 10/17/2014
Language: C++
*/
 
//Author: Taisei Yamada.

#include <iostream>
using namespace std;
double rand_float(double, double);
double rand_float_prob(double, double);
int main ()
{
    double wind_speed, maxgust, mingust, avg_windspeed, min_prob, max_prob, probability, max_avgwindspeed, min_avgwindspeed;
    int time, stormtime;
    char repeat='y';
    cout << "Welcome to the Flight Simulator Wind Speed calculator.\n";

while (repeat=='y')
{
    cout << "Enter the value for the average wind speed: ";
    cin >> avg_windspeed;
    cout << "Enter the value for the minimum gust: ";
    cin >> mingust;
    cout << "Enter the value for the maximum gust (it must be greater than the minimum gust): ";
    cin >> maxgust;
    cout << "TIME   |    " << "WINDSPEED\n";
    cout << "--------------------------\n";

for (time=0; time<=3600; time+=10)
{
    wind_speed=rand_float (min_avgwindspeed, max_avgwindspeed);
    probability = rand_float_prob(min_prob, max_prob); // probability is computed by inputting the constant minimum probability (0) and maximum probability (1)
    if (probability >=0.5)
    {
    stormtime = time+300;
    }
    
    if(stormtime)
    {
    wind_speed+=10;
    min_avgwindspeed = avg_windspeed+mingust;
    max_avgwindspeed = avg_windspeed+maxgust;
    min_prob=0;
    max_prob=1;
    cout << time << "        " << wind_speed << " *" << endl;
    stormtime -= 10;
    }
    else
    {
    cout << time << "        " << wind_speed << endl;
    }

}
    
    cout << "Would you like to continue with different values? If yes, press y or press any other key to exit otherwise.\n";
    cin >> repeat;

}
return 0;
}


double  rand_float(double min_avgwindspeed, double max_avgwindspeed)
{
    double wind_speed;
    wind_speed = ((double)rand()/RAND_MAX) * (max_avgwindspeed-min_avgwindspeed) + min_avgwindspeed;
    return wind_speed;
}

double rand_float_prob(double min_prob, double max_prob)
{
    double probability;
    probability= ((double)rand()/RAND_MAX) * (max_prob-min_prob) + min_prob;
    return probability;
}


see my edit above... your probability check is probably backwards. which is making it almost always be a storm.

Also, the for loop is a bit off
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
for (time=0; time<=3600; time+=10)
{
	wind_speed=rand_float (min_avgwindspeed, max_avgwindspeed);
	probability = rand_float_prob(min_prob, max_prob); // probability is computed by inputting the constant minimum probability (0) and maximum probability (1)
	if (probability >=0.5)
	{
		stormtime = time+300;
	}

	if(stormtime)
		wind_speed+=10;

	min_avgwindspeed = avg_windspeed+mingust;
	max_avgwindspeed = avg_windspeed+maxgust;
	min_prob=0;
	max_prob=1;

	if(stormtime)
	{
		cout << time << "        " << wind_speed << " *" << endl;
		stormtime -= 10;
	}
	else
	{
		cout << time << "        " << wind_speed << endl;
	}

}
Last edited on
My maximum probability is a 1, and my minimum is at 0 as you mentioned.
Also what do you mean that my for loop is off?
Here's your loop:
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
for (time=0; time<=3600; time+=10)
{
	wind_speed=rand_float (min_avgwindspeed, max_avgwindspeed);
	probability = rand_float_prob(min_prob, max_prob); // probability is computed by inputting the constant minimum probability (0) and maximum probability (1)
	if (probability >=0.5)
	{
	stormtime = time+300;
	}
    
	if(stormtime)
	{
	wind_speed+=10;
	min_avgwindspeed = avg_windspeed+mingust;
	max_avgwindspeed = avg_windspeed+maxgust;
	min_prob=0;
	max_prob=1;
	cout << time << "        " << wind_speed << " *" << endl;
	stormtime -= 10;
	}
	else
	{
	cout << time << "        " << wind_speed << endl;
	}

}



and here's mine:
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
for (time=0; time<=3600; time+=10)
{
	wind_speed=rand_float (min_avgwindspeed, max_avgwindspeed);
	probability = rand_float_prob(min_prob, max_prob); // probability is computed by inputting the constant minimum probability (0) and maximum probability (1)
	if (probability >=0.5)
	{
		stormtime = time+300;
	}

	if(stormtime)
		wind_speed+=10;

	min_avgwindspeed = avg_windspeed+mingust;
	max_avgwindspeed = avg_windspeed+maxgust;
	min_prob=0;
	max_prob=1;

	if(stormtime)
	{
		cout << time << "        " << wind_speed << " *" << endl;
		stormtime -= 10;
	}
	else
	{
		cout << time << "        " << wind_speed << endl;
	}

}


first thing to note is that you should always indent loops and conditionally executed code (if/switch) blocks, to reflect the structure of what's going on. If I properly indent your loop this is what you get:
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
for (time=0; time<=3600; time+=10)
{
	wind_speed=rand_float (min_avgwindspeed, max_avgwindspeed);
	probability = rand_float_prob(min_prob, max_prob); // probability is computed by inputting the constant minimum probability (0) and maximum probability (1)
	if (probability >=0.5)
	{
		stormtime = time+300;
	}
    
	if(stormtime)
	{
		wind_speed+=10;
		min_avgwindspeed = avg_windspeed+mingust;
		max_avgwindspeed = avg_windspeed+maxgust;
		min_prob=0;
		max_prob=1;
		cout << time << "        " << wind_speed << " *" << endl;
		stormtime -= 10;
	}
	else
	{
		cout << time << "        " << wind_speed << endl;
	}

}


see the difference?
Last edited on
if your min probability is 0, and max is 1, then the check for 0.5% would be "<= 0.005"
Last edited on
I totally see the difference. Looks like I messed up on the formatting as well then. So here's the code I have now
Now it just shows asteriks for about the first and last 1000 seconds
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  /*
This program will allow you to generate wind speeds between specific average wind speed values. Users will be prompted for the average wind speed, minimum and maximum windspeeds, and the program will automatically
display a table that shows the values between the maximum and minimum average windspeeds (+gust). There will be an asterik displayed for 300 seconds next to the values if a storm is encountered.
Date: 10/17/2014
Language: C++
*/
 
//Author: Taisei Yamada.

#include <iostream>
using namespace std;
double rand_float(double, double);
double rand_float_prob(double, double);
int main ()
{
    double wind_speed, maxgust, mingust, avg_windspeed, min_prob, max_prob, probability, max_avgwindspeed, min_avgwindspeed;
    int time, stormtime;
    char repeat='y';
    cout << "Welcome to the Flight Simulator Wind Speed calculator. This program allows you to generate a table of wind speeds for 3600 seconds, considering the minimum gust, maximum gust and the wind speed. Asteriks will be displayed next to ech wind speed for a duration of 300 seconds (5 minutes) if a storm is encountered. \n";

while (repeat=='y')
{
    cout << "Enter the value for the average wind speed: ";
    cin >> avg_windspeed;
    cout << "Enter the value for the minimum gust: ";
    cin >> mingust;
    cout << "Enter the value for the maximum gust (it must be greater than the minimum gust): ";
    cin >> maxgust;
    cout << "TIME   |    " << "WINDSPEED\n";
    cout << "--------------------------\n";

for (time=0; time<=3600; time+=10)
{
	wind_speed=rand_float (min_avgwindspeed, max_avgwindspeed);
	probability = rand_float_prob(min_prob, max_prob); // probability is computed by inputting the constant minimum probability (0) and maximum probability (1)
	if (probability <=0.005)
	{
		stormtime = time+300;
	}

	if(stormtime)
		wind_speed+=10;

	min_avgwindspeed = avg_windspeed+mingust;
	max_avgwindspeed = avg_windspeed+maxgust;
	min_prob=0;
	max_prob=1;

	if(stormtime)
	{
		cout << time << "        " << wind_speed << " *" << endl;
		stormtime -= 10;
	}
	else
	{
		cout << time << "        " << wind_speed << endl;
	}

}
    
    cout << "Would you like to continue with different values? If yes, press y or press any other key to exit otherwise.\n";
    cin >> repeat;

}
return 0;
}


double  rand_float(double min_avgwindspeed, double max_avgwindspeed)
{
    double wind_speed;
    wind_speed = ((double)rand()/RAND_MAX) * (max_avgwindspeed-min_avgwindspeed) + min_avgwindspeed;
    return wind_speed;
}

double rand_float_prob(double min_prob, double max_prob)
{
    double probability;
    probability= ((double)rand()/RAND_MAX) * (max_prob-min_prob) + min_prob;
    return probability;
}

it's possible that that is exactly what should be happening depending on the random values you generate. keep in mind there is nothing to prevent a new storm happening while one is currently going on. so if another storm is generated 3 minutes into a current storm, you'll end up with 8 minutes of stormtime.
ok... now I see that I made a big booboo myself.

do not set stormtime = time + 300;
that'll make 'em last a lot longer than they should. just do this:
stormtime = 300;

see... even pros screw up :)

since stormtime is an independent clock counting down form 5min (300 seconds) to 0, it should have no relation to the current time at all.
Last edited on
Yup, that actually worked!
I had to turn in my assignment with the time+300 set due to the deadline, but it's all good. Thank you very much for your help!
Topic archived. No new replies allowed.