Trouble with strings

I had to input temperatures into numbered weather stations. This time I need to address name's to each station, then input temperatures from each station.

/* Example of Desired Output

Choices...................
---------------------------
Add... Adds a Station // inputs of the Station and the Person in charge
Post....Post recorded temperatures // Displays the Station & person in charge, able to input the temperature
Daily.... Reveals inputted temperatures of the day
High-Low..... Shows the range of temperature's of the area
Quit... When you're all done
---------------------------
Enter Command: Add
Enter Station Information Below, Stop To Quit
-----------------------------------
Enter Weather Station Designation: Boston
Enter Contact Person: Peter Bishop
-----------------------------------
-----------------------------------
Enter Weather Station Designation: San Francisco
Enter Contact Person: James Wicker
-----------------------------------
-----------------------------------

Enter Weather Station Designation: Stop
Choices...................

---------------------------
Add... Adds a Station
Post....Post recorded temperatures
Daily.... Reveals inputted temperatures of the day
High-Low..... Shows the range of temperature's of the area
Quit... When you're all done

---------------------------

Enter Command: Post Temperatures
Enter reported temperatures...
Boston
Peter Bishop
Enter Temperature: 39

San Francisco
James Wicker
Enter Temperature: 62

Choices...................

---------------------------
Add... Adds a Station
Post....Post recorded temperatures
Daily.... Reveals inputted temperatures of the day
High-Low..... Shows the range of temperature's of the area
Quit... When you're all done
---------------------------
*/




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <iostream>
#include <string>
using namespace std;

struct WeatherStation {
string StationDesignation;
double Temperature;
};

struct AddStation  {
	string StationDestination;
	string Agent;
};


string nStation[5] =
		{"Boston", "San Francisco", "Detroit", "Mayfield", "Redwoods"};

void Choices();
void Add (Addstation
void Post(WeatherStation[], WeatherStation[], WeatherStation[]);
void dailyReport(WeatherStation[], WeatherStation[], WeatherStation[]);
void highLowReport(WeatherStation[], WeatherStation[]);

int main()
{
WeatherStation fStation[5];
WeatherStation cStation[5];
WeatherStation nStation[5];
string Command;

while(true)
{
Choices();
getline(cin, Command);
if(Command == "Quit")
break;
else if(Command == "Post")
Post(fStation, cStation, nStation);
else if(Command == "Daily")
dailyReport(fStation, cStation, nStation);
else if(Command == "High-Low")
highLowReport(fStation, cStation);
}
return 0;
}

void Choices()
{
cout << "Choices......" << endl;
cout <<"============================================" << endl;
cout <<"Add... Add a Station"<< endl;
cout << "Post....Post recorded tempertures." << endl;
cout << "Daily.... Reveals inputed tempertures of the day." << endl;
cout << "High-Low..... Shows the range of temperture's of the area." << endl;
cout << "Quit... When you're all done" << endl;
cout <<"============================================" << endl;
}

void Fill(AddStation* List, int MaxSize, int& Size)
{
	cout << "Enter Station Location Below, then Enter Agent's Name. Enter Stop When Finished." << endl;

	for(Size = 0 ; Size < MaxSize ; Size++)  {
		cout << "Enter Station Location: ";
		getline(cin, List[Size].StationDestination);

		cout << "Enter Agent Name: ";
		getline(cin, List[Size].Agent);
		if(List[Size].LastName == "Stop")
			break;
	}
}



void Post(WeatherStation fStation[], WeatherStation cStation[], WeatherStation nStation[])
{
int K = 0;
double Temperature;

cout <<  "============================================" << endl;
cout << "Enter the  temperatures in Fahrenheit:" << endl ;

for(K = 0; K < 5; K++)
{
cout << "WeatherStation " << nStation[K].StationDesignation << ": ";
cin >> Temperature;
fStation[K].Temperature = Temperature;
cStation[K].Temperature = (5 *((Temperature)- 32))/9;
}
}

void dailyReport(WeatherStation fStation[], WeatherStation cStation[], WeatherStation nStation[])
{
double fTotal = 0;
double cTotal = 0;
int K = 0;

cout << "NGS Temperature Report" << endl;
cout <<"	Fahrenheit | Celcius" << endl;
for(K = 0; K < 5; K++)
{
cout << "Weather Station " << nStation[K].StationDesignation << ": " << fStation[K].Temperature << "\t" << cStation[K].Temperature << endl;
fTotal += fStation[K].Temperature;
cTotal += cStation[K].Temperature;
}
cout << "Mean: " << fTotal/5 << "\t" << cTotal/5 << endl;
}

void highLowReport(WeatherStation fStation[], WeatherStation cStation[])
{
int K = 0;
double highestF = fStation[0].Temperature;
double lowestF = fStation[0].Temperature;
double highestC = cStation[0].Temperature;
double lowestC = cStation[0].Temperature;	

for (K = 0; K < 5; K++)
{
if(fStation[K].Temperature > highestF)
highestF = fStation[K].Temperature;
}

for (K = 0; K < 5; K++)
{
if(fStation[K].Temperature < lowestF)
lowestF = fStation[K].Temperature;
}

for (K = 0; K < 5; K++)
{
if(cStation[K].Temperature > highestC)
highestC = cStation[K].Temperature;
}

for (K = 0; K < 5; K++)
{
if(cStation[K].Temperature < lowestC)
highestC = cStation[K].Temperature;
}
cout << "Fahrenheit			Celcius" << endl;
cout << "Lowest: " << lowestF << "		\t" << lowestC << endl;
cout << "Highest: " << highestF << "		\t" << highestC << endl;
}
For starters, check lines 20 and 70.

After that, what exactly are you having trouble with? Defining an "Add" function? If you want to add more stations on the fly to your nStation, cStation, and fStation, I recommend making them vectors.
1
2
3
4
vector<type> name; //Creates a vector of type... type.
name.push_back(type data); //Pushes data onto the end of the vector, enlarging it.
name[int position]; //Access an element of the vector.
name.length(); //Gets the size of your vector. 

http://cplusplus.com/reference/stl/vector/

Or did I misunderstand something?

-Albatross
Last edited on
Topic archived. No new replies allowed.