Problem getting information from a structure and other problems

Essentially i have created a program that read information from a file. However i am having problems trying to access that information. I can't figure out a way. What i am trying to do is make a menu that prompts the user to select a city and a degree so that i can display the low and high temperatures for that city. My code has many problems that need to be fixed and is not finished at all but any guide or tips on what i should do would be nice.

From my bool function i was expecting to retrieve all the information from the file and pass some of the values into my display function. Then In my do while loop in the int main i was trying to give the user a choice that could be linked to the information in the structure, but i cant figure out how.

Any tips are welcomed.

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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <string>

using namespace std;

// Constants

const int NUM_MONTH = 12;

// Functions

void DisplayChart(string);
int menu(int, int , int)
bool getTemp(TemperatureInfo [], int)

// Struct

struct TemperatureInfo
{
	char scale; // F for Fahrenheit, or C for Celsius
	double low;
	double high;
	string monthName;
	
};

struct CityInfo
{
	string CityName;
	TemperatureInfo Month;
};

// Main Program
int main()
{
	
	bool getTemp(CityInfo *Cities, TemperatureInfo *Month, CityInfo[], );
	int city;
	int Temperature;
	int lowhigh;
	int choice;
	do
	{
		// trying to give the user a choice and retrieve the data from the structs
		choice = 0;
		cout << " Welcome to COP 2335 Temperature Wizard Program." << endl;
		cout << " Please select one of the following cities: " << endl;
		cout << " 1. Miami " << endl;
		cout << " 2. Key West " << endl;
		cout << " 3. Jacksonville " << endl;
		cout << " 4. Pensacola " << endl;
		cout << " 5. Exit " << endl;
		cin >> choice;

	} while (choice != 5)

	cout << "/n Good Bye!" << endl;
	DisplayChart(city); // Displainy City Chart
	


	system("PAUSE");
	return 0; 

}


void DisplayChart(int numCities, int numMonth, string CityName)
{

	// Will be the same everytime
	cout << CityName << endl;
	cout << " Month " << setfill(' ') << setw(8) << " Low " << setw(7) << " High " << endl;

	// Loop for displaying month
	for (int i = 0; i < numCities; i++)
	{
		for (int k = 0; k < numMonth; k++)
		{
			// trying to pass month name
			cout << Cities[i].Month[k].monthName << setfill(' ') << setw(10) << Cities[i].Month[k].low << setw(7) << " High " << endl;
		}
	}

	
}



bool getTemp(CityInfo *Cities, TemperatureInfo *Month, CityInfo City[], )
{
	string FileName;
	do{
		// Enter file or exit
		cout << " Enter a file location or 1 to exit: ";
		getline(cin, FileName);
		ifstream inFile(FileName.c_str(), ios::in);

		if (!inFile && FileName != "1")
		{
			cout << " File not found!" << endl;
		}
		else if (inFile)
		{
			// Firist Line Number of Cities
			int numCities
			getline(inFile, numCities);
			Cities = malloc(numCities * sizeof *Cities);

			// Number of Month for the month temperature reading loop.
			int numMonth
			getline(inFile, numMonth);
			Month = malloc(numMonth * sizeof *Month);

			// Month assigment
			string monthAssigment[11];
			monthAssigment[0] = " Jan ";
			monthAssigment[1] = " Feb ";
			monthAssigment[2] = " Mar ";
			monthAssigment[3] = " Apr ";
			monthAssigment[4] = " May ";
			monthAssigment[5] = " Jun ";
			monthAssigment[6] = " Jul ";
			monthAssigment[7] = " Agu ";
			monthAssigment[8] = " Sept";
			monthAssigment[9] = " Oct ";
			monthAssigment[10] = " Nov ";
			monthAssigment[11] = " Dec ";

			// Loops for other lines.
			
			for (int i = 0; i < numCities; i++)
			{
				getline(inFile, Cities[i].CityName, ',');
				for (int k = 0; k < numMonth; k++)
				{
					// passing the month Name
					Cities[i].Month[k].monthName = monthAssigment[k]
						if (k > 12)
						{
							cout << "/n Error. Month number higher than 12! " << endl;
							return false;
						}
					getline(inFile, Cities[i].Month[k].low, ',');
				}

				getline(inFile, Cities[i].CityName, ',');
				for (int k = 0; k < numMonth; k++)
				{
					getline(inFile, Cities[i].Month[k].high, ',');
				}
			}

			for (int i = 0; i < numCities; i++)
			{
				void DisplayChart(numCities, numMonth, Cities[i].CityName);
			}
			inFile.close();
			cout << endl << endl << endl;
			return true;
		}





	} while (FileName != "1"); // Ends loop program closes
}


Heres the Data file:
4
12
Miami,59.6,60.5,64.0,67.6,72.0,75.2,76.5,76.5,75.7,72.2,67.5,62.2
Miami,76.5,77.7,80.7,83.8,87.2,89.5,90.9,90.6,89.0,85.4,81.2,77.5
Key West,65.2,65.7,68.8,72.1,75.9,78.7,79.6,79.2,78.5,75.7,71.9,67.3
Key West,75.3,75.9,78.8,81.9,85.4,88.1,89.4 ,89.5,88.2,84.7,80.6,76.7
Jacksonville,41.9,44.3,49.8,54.6,62.5,69.4,72.4,72.2,69.4,59.7,50.8,44.1
Jacksonville,64.2,67.3,73.4,78.6,84.3,88.7,90.8,89.4,86.1,79.1,72.5,65.8
Pensacola,42.7,45.4,51.7,57.6,65.8,72.1,74.5,74.2,70.4,59.6,51.1,44.7
Pensacola,61.2,64.4,70.2,76.2,83.4,89.0,90.7,90.1,87.0,79.3,70.3,63.4
Last edited on
noob plusplus wrote:
From my bool function
noob plusplus wrote:
in the int main
Don't say it like that - the return type is not important when explaining what function you are talking about. Instead, say "my getTemp function" or "the main function".

When you compile your code, look at the first error message only and look at the line it is complaining about. Fix the problem and compile again, then repeat the process.

Line 7: bad practice

Lines 16, 17: missing semicolons at the end of the line

Line 40: What is this for? Do you mean for it to replace Line 17? It should not be inside your main function.

Line 57: You do nothing after getting input from the user, you probably want to call a function here.

Line 61: Your variable city has not been assigned a value and so is uninitialized; it just has a random garage value and is most certainly not a value you want or expect.

Line 65: bad practice, see http://www.cplusplus.com/articles/j3wTURfi/

Line 93: You have an extra comma like there is going to be another parameter, but then there isn't one. Also, this doesn't match Line 17, so it counts as an entirely different function with the same name.

Lines 111, 116: You are using C++, so try to avoid using things from C that have been replaced in C++. There are better alternatives in C++ that will make your life both safer and easier.

Lines 119-131: This should be something done once at the start of your program, not every time your loop iterates.

Line 170.5: Missing return statement (not all control paths return a value)
Thank you so much. That helped me a lot i'm still working on the code. Ill upload the fixed version later. Again thanks!
Topic archived. No new replies allowed.