Wind Simulation Project Please a little help !

This is a discussion on Wind Simulation Project Please a little help ! within the C++ Programming forums, part of the General Programming Boards category; hi guys, I'm trying to finish my wind smulation project but I'm having problems. What I'm doing is creating a ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    44

    Wind Simulation Project Please a little help !

    hi guys,

    I'm trying to finish my wind smulation project but I'm having problems.

    What I'm doing is creating a for loop to display from

    0 seconds to 3600 seconds or 1 hour of wind simulation

    My first Column displays the Time, and the second column displays the wind result which is a calculation from three inputs.

    cin >> Avg_Wind;
    cin >> High_Gust;
    cin >> Low_Gust;

    Upper_Limit = Avg_Windi + High_Gust;
    Lower_Limit = Low_Gust;

    Avg_Wind = rand_float (Upper_Limit, Lower_Limit);


    What I need to do is make some kind of calculation that would increased by 10 the Avg_Wind for a period of 300 seconds.

    I created a function on the botton but for some reason it doesn't increased by 10 for a period of 300 seconds and but adds 10 to the wind result for the whole hour
    Please give me a hand if you have more questions let me know and I will try to explain better .

    Thanks Here's what I have so far
    Code:
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    void Wind_Speed();
    void Wind_Storm();
    void Microbursts();
    void View_Wind();
    
    double rand_float(double a, double b);
    string Make_Stars (int result);
    double Small_Storm ( double Wind_Storm ); 
    double Microburst ( double result );
    
    
    
    double High_Gust;
    double Low_Gust;
    double Upper_Limit, Lower_Limit;
    double Avg_Wind;
    
    int main()
    {
    	
      char selection;
     
    	do
      {
    	
        system("cls");
    
    	cout << "   Wind speed simulation by Dilmer Valecillos CS1600-001 " << endl;
      	cout << "   -----------------------------------------------------\n\n"
    	     << "   Menu\n"
             << "   ----\n\n"
           	 << "1. Create wind speed simulation \n"
             << "2. Create wind speed with storms \n"
             << "3. Create wind speed with Microbursts \n"
             << "4. View wind simulation \n"
             << "5. Quit\n\n"
             << "   Selection: ";
    
      	//Get menu selection
      	selection = cin.get();
    
      	//Process selection
      	switch( selection)
      	{
      	  case '\n':		       break;
    	  case '1': Wind_Speed();  break;
          case '2': Wind_Storm();  break;	  
    	  case '3': Microbursts(); break;
          case '4': View_Wind();   break;
          case '5':			       break;
          default: cout << '\a';
      	}
    
      }while( selection != '5' );
    
    	return 0;
    }//end main()
    
    //Function definitions
    void Wind_Speed()
    {
    	  system("cls");
    
    	  int i = 0;
    	  int Max_Seconds = 3600;
    	
    	  ofstream wind;
    	  wind.open("wind.dat");
          
    	  cout << " |---- dilmer valecillos [cs1600-001] ----|" << endl;
    	  cout << "\n\n  Enter the average of wind speed (mhp) : " ;
    	  cin  >> Avg_Wind;
    	  cout << "\n  Enter high gusts range (mhp) : " ;
    	  cin  >> High_Gust;
    	  cout << "\n  Enter low gusts range (mhp) : " ;
    	  cin  >> Low_Gust;
    
    	  Upper_Limit = Avg_Wind + High_Gust;
    	  Lower_Limit = Avg_Wind + Low_Gust;	
    
    	  wind.setf(ios::fixed | ios::showpoint); // set formats in the file
          wind.precision(2);
    	  cout.setf(ios::fixed | ios::showpoint); // set formats to display on the screen
    	  cout.precision(2);
    	  
    	  for (i = 0; i <= Max_Seconds; i++) // seconds from 0 to max_seconds which is 3600 seconds or an hour
    	  {
    		
    	   	Avg_Wind = rand_float (Upper_Limit, Lower_Limit);
    	 
    		if ( ( i % 10 ) == 0 )
    		{
    
    		wind << setw(4) << i << "   " << Avg_Wind << endl; // Write all the data to a file called wind.dat
    		cout << setw(4) << i << "   " << Avg_Wind << " " << Make_Stars ( (int) Avg_Wind) << endl;// outputs the histogram and info to the screen
    
    		}
    	
    	  }
    			
    	  wind.close();
          system("pause");
    }
    
    void Wind_Storm()//Option 2
    {
     system("cls");
    
    	  int i = 0;
    	  int Max_Seconds = 3600;
    	  //int Storm_In;
    	  int Storm_Time = 300;
          
    
    	  ofstream wind;
    	  wind.open("wind.dat");
          
    	  cout << " |---- dilmer valecillos [cs1600-001] ----|" << endl;
    	  cout << "\n\n  Enter the average of wind speed (mhp) : " ;
    	  cin  >> Avg_Wind;
    	  cout << "\n  Enter high gusts range (mhp) : " ;
    	  cin  >> High_Gust;
    	  cout << "\n  Enter low gusts range (mhp) : " ;
    	  cin  >> Low_Gust;
    	  //cout << "\n  Enter storm probability (%) : ";
    	  //cin  >> Storm_In;
    
    
    	  Upper_Limit = Avg_Wind + High_Gust;
    	  Lower_Limit = Low_Gust;	
    
    	  wind.setf(ios::fixed | ios::showpoint); // set formats in the file
          wind.precision(2);
    	  cout.setf(ios::fixed | ios::showpoint); // set formats to display on the screen
    	  cout.precision(2);
    	  
    	  for (i = 0; i <= Max_Seconds; i++) // seconds from 0 to max_seconds which is 3600 seconds or an hour
    	  {
    
    		Avg_Wind = rand_float (Upper_Limit, Lower_Limit);
    
    		if ( ( i % 10 ) == 0 )
    		{
    
    		wind << setw(4) << i << "   " << Avg_Wind << endl; // Write all the data to a file called wind.dat
    		cout << setw(4) << i << "   " << Small_Storm(Avg_Wind) << " " << Make_Stars ( (int) Avg_Wind) << endl;// outputs the histogram and info to the screen
            
    		}
    	
    	  }
    		
    	  wind.close();
          system("pause");
    }
    
    void Microbursts()//Option 3
    {
    system("cls");
    
    	  int i = 0;
    	  int Max_Seconds = 3600;
    	  
    	  
          
    
    	  ofstream wind;
    	  wind.open("wind.dat");
          
    	  cout << " |---- dilmer valecillos [cs1600-001] ----|" << endl;
    	  cout << "\n\n  Enter the average of wind speed (mhp) : " ;
    	  cin  >> Avg_Wind;
    	  cout << "\n  Enter high gusts range (mhp) : " ;
    	  cin  >> High_Gust;
    	  cout << "\n  Enter low gusts range (mhp) : " ;
    	  cin  >> Low_Gust;
    
    	  Upper_Limit = Avg_Wind + High_Gust;
    	  Lower_Limit = Avg_Wind + Low_Gust;	
    
    	  wind.setf(ios::fixed | ios::showpoint); // set formats in the file
          wind.precision(2);
    	  cout.setf(ios::fixed | ios::showpoint); // set formats to display on the screen
    	  cout.precision(2);
    	  
    	  for (i = 0; i <= Max_Seconds; i++) // seconds from 0 to max_seconds which is 3600 seconds or an hour
    	  {
    
    		if ( ( i % 10 ) == 0 )
    		{
    
    		wind << setw(4) << i << "   " << Avg_Wind << endl; // Write all the data to a file called wind.dat
    		cout << setw(4) << i << "   " << Microburst(Avg_Wind) << " " << Make_Stars ( (int) Avg_Wind) << endl;// outputs the histogram and info to the screen
            
    		}
    	
    	  }
    		
    	  wind.close();
          system("pause");
    }
    
    void View_Wind()
    {
        system("cls");
      
    	int seconds; // since the first column is a whole number i declate it as a int
    	double Wind_Speed; // the wind result in the second column has decimals so it must be a double number
    
    	ifstream read_file; //to read info from a file
    
    	read_file.open("wind.dat"); // to open the file for reading 
    
    	read_file  >>  seconds >> Wind_Speed; // read first and second column in this case seconds and wind speed 
    
    	while (! read_file.eof()) // read the data until the end of the file
    	
    	{
    
    	read_file  >>  seconds >> Wind_Speed; // read the first column and the second colum of the file 
    	cout << setw(4) << seconds << "  " << Wind_Speed <<  endl; // show the info on the screen with a width of 4 		
    	
    	}
    	
    	read_file.close(); // close the file
        system("pause");
    }
    
    double rand_float (double a, double b)
    
    {
    	return ((double) rand() / RAND_MAX ) * (b - a) + a;
    }
    
    string Make_Stars (int result) // Histogram Function 
    
    {
    	int i;
    	string Stars;
    
    	for ( i = 1; i <= Avg_Wind; i++)
    	{
    		Stars += "*";
    	}
    
    	return Stars;
    }
    
    double Small_Storm ( double Storm ) //Returns a value and Adds 10 mph to the Average for five minutes of Storm
    {
    	int Storm_Time = 300;
     
        for ( int x = 0; x < Storm_Time; x++)
    	{
    			
    	return Avg_Wind = rand_float (Upper_Limit + 10, Lower_Limit + 10);
    			
    	}
    
    }
    
    double Microburst ( double result )
    
    {
    
    	int Time = 60;
    	
    	for ( int x = 0; x < Time; x++)
    	{
    	 
    	return Avg_Wind = rand_float (Upper_Limit + 25, Lower_Limit + 25);
    
    	}
    }

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    > cout << setw(4) << i << " " << Small_Storm(Avg_Wind) <<

    if(i<300)cout<<set(4)<<i<<" "<<small_Storm(avg_wind).


    Code:
    double Small_Storm ( double Storm ) //Returns a value and Adds 10 mph to the Average for five minutes of Storm
    {
    	int Storm_Time = 300;
     
        for ( int x = 0; x < Storm_Time; x++)
    	{
    			
    	return Avg_Wind = rand_float (Upper_Limit + 10, Lower_Limit + 10);
    			
    	}
    
    }
    the loop is not required.

    and u r not passing the value of upper_limit or lower_limit
    Last edited by qqqqxxxx; 03-23-2006 at 02:59 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 08:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21