Problem

What does this program display? I know it has errors in it but I have no idea how to fix them. By the way, I am very new to this. :)

Any ideas?

#include "stdafx.h"
#include<iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[]);
int setw;
{
int arr_3d[4][3] = {{1},
{1, 2},
{1, 2, 3},
{1, 2, 3, }};
int row, col;
for (row = 0; row < 4; ++row)
{
cout << endl;
for (col = 0; row < 3; ++col)
cout << setw(3) << arr_3d[row][col];
}
return 0;
}



Here are the errors:

1>------ Build started: Project: classdiscussion2, Configuration: Debug Win32 ------
1> classdiscussion2.cpp
1>c:\users\mjlhr\documents\visual studio 2010\projects\classdiscussion2\classdiscussion2\classdiscussion2.cpp(11): error C2447: '{' : missing function header (old-style formal list?)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
You're declaring a 4x3 array and attempting to initialise it with something that's not a 4x3 array.
That's a bit confusing to me. Is there any possible way you could explain that a little better?

Thanks :)
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
#include <iostream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[])
{
	int arr_3d[4][3] =
	{
		{1, 0, 0 },
		{1, 2, 0 },
		{1, 2, 3 },
		{1, 2, 3 }
	};

	for (int row = 0; row < 4; ++row)
	{
		for (int col = 0; col < 3; ++col)
		{
 			cout << setw(3) << arr_3d[row][col];
		}
		cout << endl;
	}

	return 0;
}
Last edited on
Topic archived. No new replies allowed.