5 Replies - 245 Views - Last Post: 05 November 2017 - 08:45 PM Rate Topic: -----

#1 11ash1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 25-October 15

My Program Is Giving Declaration Errors

Posted 05 November 2017 - 07:14 PM

Hello, my program is giving me declaration errors. I am not sure what is wrong so can someone help? thank you.

C++ program:
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include<string>
#include <stdlib.h>
#include<vector>

#include<sstream>

using namespace std;

struct Weather_Station
{
	string name;
	double temperature;
	double windspeed;
	string windDirection;
};

string DisplayMenu(string station_name)
{
	string str, temp;
	do
	{
		cout << "*******************WEATHER STATION: " << station_name\
			<< " *******************" << endl << endl;
		cout << "I. Input a complete weather reading." << endl;
		cout << "P. Print the current weather." << "\n";
		cout << "H. Print the weather history (from most recent to oldest)." << endl;
		cout << "E. Exit the program." << "\n";
		cout << "Enter your choice: " << endl;
		cin >> str;
		temp = str;
		for (std::string::size_type i = 0; i < str.length(); ++i)
			temp[i] = toupper(str[i]);
		str = temp;
	} while (!(str == "I" || str == "P" || str == "H" || str == "E"));

	return str;

}

double getTemperature()

{

	double temp;

	string temp_string;

	stringstream converter;

	cout << "Enter the temperature: ";

	cin >> temp_string;

	converter << temp_string;

	converter >> temp;

	return temp;

}
double getWindSpeed()

{

	double temp;

	string temp_string;

	stringstream converter;

	//this loop will be iterated continuously untill user enters windspeed which is greater than zero
	cout << "Enter Wind speed: ";

	cin >> temp_string;

	converter << temp_string;

	converter >> temp;

	if (temp <= 0)
		cout << "Wind speed should be always greater than 0(zero)"

};
while (temp <= 0);

	return temp;

	}
string getWindDirection()
{
	string temp_string, temp;

	do {
		cout << "Enter the Wind Direction (North,South,East,West): ";
		cin >> temp_string;
		temp = temp_string;
		for (std::string::size_type i = 0; i < temp_string.length(); ++i)
			temp[i] = toupper(temp_string[i]);

	} while (!(temp == "NORTH" || temp == "SOUTH" || temp == "EAST" || temp == "WEST" || temp == "N" || temp == "S" || temp == "E") || temp == "W");

	temp_string = temp;
	if (temp_string == "N")
		temp_string = "NORTH";
	if (temp_string == "S")
		temp_string = "SOUTH";
	if (temp_string == "W")
		temp_string = "WEST";
	if (temp_string == "E")
		temp_string = "EAST";
	return temp_string;

};

void printWeather(Weather_Station ws)
{
	cout << "Station Name " << ws.name << endl;
	cout << "Temperature " << ws.temperature << endl;
	cout << "Wind Direction " << ws.windDirection << endl;
	cout << "Wind Speed " << ws.windspeed << endl;
	cout << endl;
}
int main()
{
	//Have the user provide a name for the weather station upon entry.

	vector<Weather_Station> myStation;

	Weather_Station myWeather_Details;

	string station_name, input_choice;

	int histCount = 0;

	cout << "Enter the name of Weather Station: ";

	getline(cin, station_name);

	myWeather_Details.name = station_name;
	while (1)
	{

		//Control loop to perform various actions

		input_choice = DisplayMenu(station_name);

		if (input_choice == "I")
		{

			// get the details

			myWeather_Details.temperature = getTemperature(); // get temperature

			myWeather_Details.windDirection = getWindDirection(); //get wind direction
			myWeather_Details.windspeed = getWindSpeed(); //get wind direction
														  //store the details
			myStation.push_back(myWeather_Details);

		}
		else if (input_choice == "P")
		{
			cout << "*************Printing Current Weather*************" << endl;
			printWeather(myStation.back());
		}
		else if (input_choice == "H")
		{
			//this loop will be iterated continuously untill user gives the input count more than 0 and it is not greater than available record count in vector
			do {
				cout << "Please enter how many records you want" << "\n";
				cin >> histCount;

				if (histCount <= 0)
					cout << "Input record count should always be greater than 0(zero)"<<"\n";
				else if (histCount>myStation.size())
					cout << "Input record count shouldn't be more than available record count"<<"\n";


			} while (histCount <= 0 || histCount>myStation.size());

			cout << "*************Printing Weather History*************" << endl;
			vector<Weather_Station>::reverse_iterator rit;
			for (rit = myStation.rbegin(); rit != myStation.rend(); rit++)
				printWeather(*rit);
		}
		else if (input_choice == "E")
		{
			exit(0);
		}
	}

	return 0;
}


The declaration errors are on lines 90,92,94,119
I am not sure how to fisx this issue so I would really appreciate it if someone could help me.

Is This A Good Question/Topic? 0
  • +

Replies To: My Program Is Giving Declaration Errors

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2014
  • View blog
  • Posts: 5,397
  • Joined: 27-December 05

Re: My Program Is Giving Declaration Errors

Posted 05 November 2017 - 07:31 PM

First solve the semicolon errors and you will probably see what else is wrong.
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3716
  • View blog
  • Posts: 13,476
  • Joined: 08-August 08

Re: My Program Is Giving Declaration Errors

Posted 05 November 2017 - 08:13 PM

You should choose a language and stick with it. Based on your code I suggest C++.
If your IDE can auto indent for you, use it. Proper indenting will show problems like yours.
Was This Post Helpful? 0
  • +
  • -

#4 11ash1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 25-October 15

Re: My Program Is Giving Declaration Errors

Posted 05 November 2017 - 08:28 PM

This is the main part of the code that is having issues
	if (temp <= 0)
		cout << "Wind speed should be always greater than 0(zero)";
}
while (temp >= 0);

	return temp;

	 }

Was This Post Helpful? 0
  • +
  • -

#5 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2014
  • View blog
  • Posts: 5,397
  • Joined: 27-December 05

Re: My Program Is Giving Declaration Errors

Posted 05 November 2017 - 08:30 PM

Yes, exactly. And which function is that while statement located in? Look carefully at the braces {} .
Was This Post Helpful? 0
  • +
  • -

#6 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 1378
  • View blog
  • Posts: 4,323
  • Joined: 20-March 10

Re: My Program Is Giving Declaration Errors

Posted 05 November 2017 - 08:45 PM

I replied to this on the main thread.. didn't see this one till now...

11ash1 stop creating new threads on the same program please !
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1