ulvis.paste.net - pastebin

Paste Search Dynamic
Recent pastes
Weather
  1. //
  2.  
  3. #include <iostream>
  4.  
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. //moving outside main function
  10. string weatherStation;
  11. //array size = 5
  12. //const int HISIZE = 5;
  13. //int HISZE=0;
  14. //int menu=1;
  15. //int temperature = 111111;
  16. //double * temperature= new double[HISZE];
  17. //int windSpeed = 111111;
  18. //double * windSpeed= new double[HISZE];
  19. //string windDirection = "1";
  20. //string * windDirection=new string[HISZE];
  21. bool tempcheck = 0;
  22. bool speeddirection = 0;
  23.  
  24. int temporary=0;
  25. int holder=0;
  26. //Structure called members
  27. struct Members{
  28.     double temperature;
  29.     double windSpeed;
  30.     string windDirection;
  31. };
  32. //input data into the structures
  33. Members memberInputs(Members iMember[]){
  34.     //local placeholder for holder variable
  35.     int myvar = holder;
  36.     cout << "Enter the temperature in fahrenheit " << endl;
  37.     cin >>iMember[myvar].temperature;
  38.    
  39.    
  40.     cout << "enter the wind speed in mph and wind direction " << endl;
  41.     cin >> iMember[myvar].windSpeed;
  42.     cin >> ws;
  43.     getline(cin >> std::ws, iMember[myvar].windDirection);
  44.    
  45.    
  46.     temporary++;
  47.     holder++;
  48.     return iMember[myvar];
  49. }
  50. //be able to print out data from structures
  51. void memberPrinter(Members i[], int HISZE){
  52.     if(holder <= HISZE){
  53.         cout << " Temperature: " << i[holder - 1].temperature << " Wind speed:"
  54.         << i[holder - 1].windSpeed
  55.         << " Wind direction:" << i[holder - 1].windDirection << endl;
  56.  
  57.     }
  58.     else {
  59.         cout << " Temperature: " << i[HISZE-1].temperature
  60.         << " Wind speed:" << i[HISZE - 1].windSpeed
  61.         << " Wind direction:" << i[HISZE - 1].windDirection << endl;
  62.     }
  63.  
  64. }
  65. void inputs(int HISZE, Members *member){
  66.    
  67.    
  68.     for(int i = HISZE - 2; i > -1; i--){
  69.         member[i+1].temperature = member[i].temperature;
  70.         member[i+1].windSpeed = member[i].windSpeed;
  71.         member[i+1].windDirection = member[i].windDirection;
  72.     }
  73.     cout <<"enter temperature in fahreinheit"<<endl;
  74.     cin >>member[0].temperature;
  75.    
  76.     //tempcheck = true;
  77.    
  78.     cout <<"enter the wind speed in mph and wind direction" <<endl;
  79.     cin>>member[0].windSpeed;
  80.     cin>>ws;
  81.     getline(cin,member[0].windDirection);
  82.    
  83.    
  84.    
  85.     // speeddirection = true;
  86.     temporary++;
  87.     cout<<"Enter a number to continue:"<<endl<<" 1: input values" <<endl<<" 2: print out input values" <<endl<<" 3: See Past "<<HISZE<<" Weather Inputs"<<endl<<" 4: to end the program"<<endl;
  88. }
  89.  
  90. void printing(int HISZE, Members *member){
  91.     cout<<weatherStation<<endl;
  92.     if(temporary==0){
  93.         cout<<"Error. No input for temperature"<<endl;
  94.     }
  95.     else {
  96.         cout<<"The temperature is " <<member[0].temperature <<" Fahreinheit"<< endl;
  97.     }
  98.     if(temporary==0){
  99.         cout<<"Error. No input for wind speed and or wind direction"<<endl;
  100.     }
  101.     else{
  102.         cout << "The Windspeed is" << " " << member[0].windSpeed << " mph"<< " " << member[0].windDirection << endl;
  103.        
  104.     }
  105.    
  106.     cout<<"Enter a number to continue:"<<endl<<" 1: input values" <<endl<<" 2: print out input values" <<endl<<" 3: See Past "<<HISZE<<" Inputs"<<endl<<" 4: to end the program"<<endl;
  107. }
  108. void printHistory(int HISZE, Members *member){
  109.     // Checks if temporary is empty
  110.     if(temporary == 0)
  111.         cout<<"There are no records found"<<endl;
  112.     // If temporary is less than five
  113.     //  else if(temporary < 5)
  114.     //     cout<<"The array has less than 5 records"<<endl;
  115.    
  116.     // More than 5 records
  117.     else
  118.     {
  119.         cout<<"Last Weather Data Inputs"<<endl;
  120.         cout<<weatherStation<<endl;
  121.         // Loops X-amount of times to displays information
  122.         for(int i = 0; i < temporary && i < HISZE; i++)
  123.             cout<<"The Temperature is: "<<member[i].temperature<<" degrees Fahreinheit"<<endl
  124.             <<"The Wind Speed is: "<<member[i].windSpeed<<" mph "<<member[i].windDirection<<endl;
  125.     }
  126.    
  127.     cout<<"Enter a number to continue:"<<endl<<" 1: input values" <<endl<<" 2: print out input values" <<endl<<" 3: See Past "<<HISZE<<" Weather Inputs"<<endl<<" 4: to end the program"<<endl;
  128. }
  129.  
  130.  
  131. int main()
  132. {
  133.     int HISZE = 0;
  134.     //int* HISZE = new int;
  135.     //creates the weather station string
  136.    
  137.     /*  string weatherStation;
  138.      int menu=1;
  139.      int temperature = 111111;
  140.      int windSpeed = 111111;
  141.      string windDirection = "1";
  142.      bool tempcheck = 0;
  143.      bool speeddirection = 0; */
  144.    
  145.     //loops weather station if nothing is entered
  146.     while(weatherStation.empty()){
  147.         cout<<"Please enter the name of the Weather Station"<<endl;
  148.         getline(cin, weatherStation);
  149.         if(weatherStation == ""){
  150.             cout<<"Weather Station not entered"<<endl;
  151.         }
  152.     }
  153.     while(HISZE==0){
  154.         cout<<"Please enter how many inputs you want: "<<endl;
  155.         cin>>HISZE;
  156.         if (HISZE == 0){
  157.             cout<<"No inputs entered"<<endl;
  158.         }
  159.     }
  160.    
  161.      Members* member=new Members[HISZE];
  162.     int menu = 1;
  163.     /*  int menu=1;
  164.      float temperature = 111111;
  165.      float windSpeed = 111111;
  166.      string windDirection = "1";
  167.      bool tempcheck = 0;
  168.      bool speeddirection = 0;*/
  169.    
  170.     cout<<"Enter a number to continue:"<<endl<<" 1: input values" <<endl<<" 2: print out input values" <<endl<<" 3: See Past "<<HISZE<<" Weather Inputs"<<endl<<" 4: to end the program"<<endl;
  171.     //loops unless entered 3 and it ends program
  172.     while(menu !=4){
  173.         cin>>menu;
  174.        
  175.         //switch statement
  176.         switch(menu){
  177.                 //input option
  178.             case 1:
  179.                 inputs(HISZE,member);
  180.                 break;
  181.                 //Prints the inputs given in option 1 unless no input given
  182.             case 2:
  183.                 printing(HISZE,member);
  184.                
  185.                 break;
  186.                 //Prints the last 5 inputs from weather history
  187.             case 3:
  188.                 printHistory(HISZE,member);
  189.                 break;
  190.                 //Ends the program when user enters 4
  191.             case 4:
  192.                 return 1;
  193.                 break;
  194.                 //prints this error statement if user presses anything other than 1,2, or 3
  195.             default:
  196.                 cout<<"Sorry. The variable entered is not valid"<<endl;
  197.                 cout<<"Enter a number to continue:"<<endl<<" 1: input values" <<endl<<" 2: print out input values" <<endl<<" 3: See Past "<<HISZE<<" Weather Inputs"<<endl<<" 4: to end the program"<<endl;
  198.                 break;
  199.         }
  200.     }
  201.     return 0;
  202.    
  203.    
  204. }
Parsed in 0.051 seconds