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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
double fRand(double wmin, double wmax,double d)
{
double f = (double)rand() / RAND_MAX;
return d=wmin + f * (wmax - wmin);
}
int main ()
{
srand(time(NULL));
ofstream outfile;
outfile.open("winds.txt");
outfile<<"Time(s)\tWind Speed(m/h)"<<endl; //header
double d, wmax, wmin, wspd[360]={0};
cout<<"Input the maximum and mimimum windspeed"<<endl;
cin>>wmax>>wmin;
bool st=0, STORM=0,mb=0, MB=0;
int count, count2;
string r,r2;
cout<<"Storms? (Y/N)"<< endl;
cin >>r;
if (r=="Y")
{
cout<<"Storms are enabled."<<endl;
st = 1;
cout<<"Microbursts? (Y/N)"<< endl;
cin >>r2;
if (r2=="Y")
{
cout<<"Storms are enabled. Microbursts are enabled."<<endl;
mb=1;
}
else
{
cout<<"Storms are enabled. Microbursts are disabled"<<endl;
mb=0;
}
}
else
{
cout<<"Storms are disabled."<<endl;
st = 0;
}
for (int i; i<360; i++)
{
if (st==1 && STORM==0) //chance of a storm
{
int luck = (rand()%(200-1+1)+1);
if (i==10) //starts the storm if random number hits 13
{
STORM = 1;
count = 0; //count is used to control the storm
}
}
if (STORM==1)
{
count++;
if (MB==0&&mb==1)
{
int luck = rand()%(100-1+1)+1;
if (i==15)
{
MB=1;
count2=0;
}
}
}
if (MB==1)
{
count2++; //!!!REFUSES TO WORK AFTER THIS STATEMENT
}
if (STORM==0)
{
wspd[i]= fRand(wmin,wmax,d);
}
else if(STORM==1)
{
wspd[i]= fRand(wmin,wmax,d) + 10; //ads 10 to the wind value if there's a storm
}
int i1=i+1;
outfile<<i1<<"0\t"<<wspd[i]<<endl; //writes to the file
if (count == 60) //stops the storm after 600 seconds
{
STORM=0;
}
}
cout <<wspd[1];
return 0;
}
|