Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- #include <iostream>
- #include <string>
- using namespace std;
- //moving outside main function-global variables
- string weatherStation;
- bool tempcheck = 0;
- bool speeddirection = 0;
- int temporary=0;
- int holder=0;
- //Structure called members
- struct Members{
- double temperature;
- double windSpeed;
- string windDirection;
- };
- void inputs(int HISZE, Members *member){
- for(int i = HISZE - 2; i > -1; i--){
- member[i+1].temperature = member[i].temperature;
- member[i+1].windSpeed = member[i].windSpeed;
- member[i+1].windDirection = member[i].windDirection;
- }
- cout <<"enter temperature in fahreinheit"<<endl;
- cin >>member[0].temperature;
- //tempcheck = true;
- cout <<"enter the wind speed in mph and wind direction" <<endl;
- cin>>member[0].windSpeed;
- cin>>ws;
- getline(cin,member[0].windDirection);
- temporary++;
- 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;
- }
- void printing(int HISZE, Members *member){
- cout<<weatherStation<<endl;
- if(temporary==0){
- cout<<"Error. No input for temperature"<<endl;
- }
- else {
- cout<<"The temperature is " <<member[0].temperature <<" Fahreinheit"<< endl;
- }
- if(temporary==0){
- cout<<"Error. No input for wind speed and or wind direction"<<endl;
- }
- else{
- cout << "The Windspeed is" << " " << member[0].windSpeed << " mph"<< " " << member[0].windDirection << endl;
- }
- 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;
- }
- void printHistory(int HISZE, Members *member){
- // Checks if temporary is empty
- if(temporary == 0)
- cout<<"There are no records found"<<endl;
- // If temporary is less than five
- // else if(temporary < 5)
- // cout<<"The array has less than 5 records"<<endl;
- // More than 5 records
- else
- {
- cout<<"Last Weather Data Inputs"<<endl;
- cout<<weatherStation<<endl;
- // Loops X-amount of times to displays information
- for(int i = 0; i < temporary && i < HISZE; i++)
- cout<<"The Temperature is: "<<member[i].temperature<<" degrees Fahreinheit"<<endl
- <<"The Wind Speed is: "<<member[i].windSpeed<<" mph "<<member[i].windDirection<<endl;
- }
- 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;
- }
- int main()
- {
- int HISZE = 0;
- //loops weather station if nothing is entered
- while(weatherStation.empty()){
- cout<<"Please enter the name of the Weather Station"<<endl;
- getline(cin, weatherStation);
- if(weatherStation == ""){
- cout<<"Weather Station not entered"<<endl;
- }
- }
- //user inputs the amount of inputs they want stored in history
- while(HISZE==0){
- cout<<"Please enter how many inputs you want: "<<endl;
- cin>>HISZE;
- if (HISZE == 0){
- cout<<"No inputs entered"<<endl;
- }
- }
- //member pointer
- Members* member=new Members[HISZE];
- //menu int
- int menu = 1;
- 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;
- //loops unless entered 3 and it ends program
- while(menu !=4){
- cin>>menu;
- //switch statement
- switch(menu){
- //input option
- case 1:
- inputs(HISZE,member);
- break;
- //Prints the inputs given in option 1 unless no input given
- case 2:
- printing(HISZE,member);
- break;
- //Prints the last 5 inputs from weather history
- case 3:
- printHistory(HISZE,member);
- break;
- //Ends the program when user enters 4
- case 4:
- return 1;
- break;
- //prints this error statement if user presses anything other than 1,2, or 3
- default:
- cout<<"Sorry. The variable entered is not valid"<<endl;
- 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;
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement