Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.81 KB | None | 0 0
  1. //
  2.  
  3. #include <iostream>
  4.  
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. //moving outside main function-global variables
  10. string weatherStation;
  11. bool tempcheck = 0;
  12. bool speeddirection = 0;
  13.  
  14. int temporary=0;
  15. int holder=0;
  16. //Structure called members
  17. struct Members{
  18.     double temperature;
  19.     double windSpeed;
  20.     string windDirection;
  21. };
  22.  
  23. void inputs(int HISZE, Members *member){
  24.    
  25.    
  26.     for(int i = HISZE - 2; i > -1; i--){
  27.         member[i+1].temperature = member[i].temperature;
  28.         member[i+1].windSpeed = member[i].windSpeed;
  29.         member[i+1].windDirection = member[i].windDirection;
  30.     }
  31.     cout <<"enter temperature in fahreinheit"<<endl;
  32.     cin >>member[0].temperature;
  33.    
  34.     //tempcheck = true;
  35.    
  36.     cout <<"enter the wind speed in mph and wind direction" <<endl;
  37.     cin>>member[0].windSpeed;
  38.     cin>>ws;
  39.     getline(cin,member[0].windDirection);
  40.    
  41.    
  42.    
  43.     temporary++;
  44.     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;
  45. }
  46.  
  47. void printing(int HISZE, Members *member){
  48.     cout<<weatherStation<<endl;
  49.     if(temporary==0){
  50.         cout<<"Error. No input for temperature"<<endl;
  51.     }
  52.     else {
  53.         cout<<"The temperature is " <<member[0].temperature <<" Fahreinheit"<< endl;
  54.     }
  55.     if(temporary==0){
  56.         cout<<"Error. No input for wind speed and or wind direction"<<endl;
  57.     }
  58.     else{
  59.         cout << "The Windspeed is" << " " << member[0].windSpeed << " mph"<< " " << member[0].windDirection << endl;
  60.        
  61.     }
  62.    
  63.     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;
  64. }
  65. void printHistory(int HISZE, Members *member){
  66.     // Checks if temporary is empty
  67.     if(temporary == 0)
  68.         cout<<"There are no records found"<<endl;
  69.     // If temporary is less than five
  70.     //  else if(temporary < 5)
  71.     //     cout<<"The array has less than 5 records"<<endl;
  72.    
  73.     // More than 5 records
  74.     else
  75.     {
  76.         cout<<"Last Weather Data Inputs"<<endl;
  77.         cout<<weatherStation<<endl;
  78.         // Loops X-amount of times to displays information
  79.         for(int i = 0; i < temporary && i < HISZE; i++)
  80.             cout<<"The Temperature is: "<<member[i].temperature<<" degrees Fahreinheit"<<endl
  81.             <<"The Wind Speed is: "<<member[i].windSpeed<<" mph "<<member[i].windDirection<<endl;
  82.     }
  83.    
  84.     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;
  85. }
  86.  
  87.  
  88. int main()
  89. {
  90.     int HISZE = 0;
  91.     //loops weather station if nothing is entered
  92.     while(weatherStation.empty()){
  93.         cout<<"Please enter the name of the Weather Station"<<endl;
  94.         getline(cin, weatherStation);
  95.         if(weatherStation == ""){
  96.             cout<<"Weather Station not entered"<<endl;
  97.         }
  98.     }
  99.     //user inputs the amount of inputs they want stored in history
  100.     while(HISZE==0){
  101.         cout<<"Please enter how many inputs you want: "<<endl;
  102.         cin>>HISZE;
  103.         if (HISZE == 0){
  104.             cout<<"No inputs entered"<<endl;
  105.         }
  106.     }
  107.     //member pointer
  108.      Members* member=new Members[HISZE];
  109.    
  110.     //menu int
  111.     int menu = 1;
  112.    
  113.     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;
  114.     //loops unless entered 3 and it ends program
  115.     while(menu !=4){
  116.         cin>>menu;
  117.        
  118.         //switch statement
  119.         switch(menu){
  120.                 //input option
  121.             case 1:
  122.                 inputs(HISZE,member);
  123.                 break;
  124.                 //Prints the inputs given in option 1 unless no input given
  125.             case 2:
  126.                 printing(HISZE,member);
  127.                
  128.                 break;
  129.                 //Prints the last 5 inputs from weather history
  130.             case 3:
  131.                 printHistory(HISZE,member);
  132.                 break;
  133.                 //Ends the program when user enters 4
  134.             case 4:
  135.                 return 1;
  136.                 break;
  137.                 //prints this error statement if user presses anything other than 1,2, or 3
  138.             default:
  139.                 cout<<"Sorry. The variable entered is not valid"<<endl;
  140.                 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;
  141.                 break;
  142.         }
  143.     }
  144.     return 0;
  145.    
  146.    
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement