2 DIM Array issues

I am trying to write a code that inputs the temp. for two different cities. then outputs the city by name such as Boston and Denver as well as changes to output the actual day of the week instead of using a number so it would have an output that looks like this:

Enter all temperatures for a week of first city and then second city:
City 1, Day 1 :33

(then turn around and output this)

Boston
Sunday
Temperature: 33

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

#include <iostream>
#include <array>
using namespace std;


const int CITY = 2;
const int WEEK = 7;
const char DAY = 7["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
void getCity(int temperature);
void getName(int CITY);
//void output(char DAY, int CITY, int WEEK);


int main()
{
	int l, g;

	void getCity(int temperature);
	void getName(int CITY);
	//void output(char DAY,int CITY, int WEEK);
	for (int l = 0; l < 2; ++l)
	{
		for (int g = 0; g < 7; ++g)
		{
			cout << CITY[l] << endl;
			cout << DAY[g] << " " << WEEK[g] << endl;
		}
	}

return 0;
}

void getCity(int temperature)
{
	int temperature[CITY][WEEK];


	cout << "Enter all temperature for a week of first city and then second city. \n";


	for (int i = 0; i < CITY; ++i)
	{
		for (int j = 0; j < WEEK; ++j)
		{
		
			cout << "City " << i + 1 << ", Day " << j + 1 << " : ";
			cin >> temperature[i][j];
		}
	}

}

void getName(int CITY)
{
	if (CITY == 1)
	{
		cout << "Boston" << endl;
	}

	if (CITY == 2)
	{
		cout << "Denver" << endl;
	}

}

//void output(char DAY, int CITY, int WEEK)
//{
	//for (int s = 0; s < DAY; ++s)
	//{
		//cout << "The temperature for the last week in Boston and Denver are as follows :" << endl;
		//cout << CITY << " " << DAY << " " << WEEK << endl;
	//}
//} 
Last edited on
Step 1: take a breath.

Step 2: please, tell me your teacher has never taught you to write that:
const char DAY = 7["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

(hint: try this way (just an example):
1
2
const char * DAY[] = { "Monday", "Tuesday",  "Wednesday", "Thursday",
                       "Friday", "Saturday", "Sunday" };


Step 3: please, inform us if you’re allowed to use std::string and std::vector (you included <array>…).

Step 4: have a look at your getCity() function:
1
2
3
void getCity(int temperature)
{
	int temperature[CITY][WEEK];


If it has got int temperature as an argument, you can’t redefine it as a 2D C-style array immediately after.

Step 5: please, have a look at your getName() function:
1
2
3
4
5
const int CITY = 2;
. . .
void getName(int CITY)
{
	if (CITY == 1)

You’re hiding a global variable - well, ok, that’s nothing bad in that, but I wonder if you’re doing that on purpose…

Step 6: there’s a number of errors in your code. Please let us know if:
- you feel confident with C-style arrays (pointers vs arrays, array of pointers, 2d-arrays...);
- you know about function parameters, function prototypes, scope…;
- is this an assignment?

this is a homework assignment I've been working on between jobs and class
Topic archived. No new replies allowed.