#include <iostream> int main () int a[2][3] = { {20, 30, 10}, {60, 80, 90}}; int
ID: 3535866 • Letter: #
Question
#include <iostream>
int main ()
int a[2][3] = { {20, 30, 10}, {60, 80, 90}};
int row, col;
for(row = 0; row < 2; ++row)
{
for(col = 0; col < 3; col++)
cout << a[row][col] << " ";
cout << endl;
}
I am using Visual Studio 2010 and when I go to run the program I am getting these errors.
1>------ Build started: Project: COMP220W1Problem2, Configuration: Debug Win32 ------
1>Build started 5/9/2013 9:56:26 AM.
1>InitializeBuildStatus:
1> Touching "DebugCOMP220W1Problem2.unsuccessfulbuild".
1>ClCompile:
1> COMP220W1Problem2.cpp
1>\ilabsshome$d01497232my documentsisual studio 2010projectscomp220w1problem2comp220w1problem2comp220w1problem2.cpp(4): error C2144: syntax error : 'int' should be preceded by ';'
1>\ilabsshome$d01497232my documentsisual studio 2010projectscomp220w1problem2comp220w1problem2comp220w1problem2.cpp(6): error C2059: syntax error : 'for'
1>\ilabsshome$d01497232my documentsisual studio 2010projectscomp220w1problem2comp220w1problem2comp220w1problem2.cpp(6): error C2143: syntax error : missing ')' before ';'
1>\ilabsshome$d01497232my documentsisual studio 2010projectscomp220w1problem2comp220w1problem2comp220w1problem2.cpp(6): error C2143: syntax error : missing ';' before '<'
1>\ilabsshome$d01497232my documentsisual studio 2010projectscomp220w1problem2comp220w1problem2comp220w1problem2.cpp(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\ilabsshome$d01497232my documentsisual studio 2010projectscomp220w1problem2comp220w1problem2comp220w1problem2.cpp(6): error C2086: 'int row' : redefinition
1> \ilabsshome$d01497232my documentsisual studio 2010projectscomp220w1problem2comp220w1problem2comp220w1problem2.cpp(5) : see declaration of 'row'
1>\ilabsshome$d01497232my documentsisual studio 2010projectscomp220w1problem2comp220w1problem2comp220w1problem2.cpp(6): error C2059: syntax error : '++'
1>\ilabsshome$d01497232my documentsisual studio 2010projectscomp220w1problem2comp220w1problem2comp220w1problem2.cpp(6): error C2059: syntax error : ')'
1>\ilabsshome$d01497232my documentsisual studio 2010projectscomp220w1problem2comp220w1problem2comp220w1problem2.cpp(7): error C2143: syntax error : missing ';' before '{'
1>\ilabsshome$d01497232my documentsisual studio 2010projectscomp220w1problem2comp220w1problem2comp220w1problem2.cpp(7): error C2447: '{' : missing function header (old-style formal list?)
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.13
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I am stuck and not sure how to fix. Also what would be the output?
Explanation / Answer
you forgot to put the entire main function in curly brackets. and also you must also use "using namespace std;" before main() The correct code is: #include using namespace std; int main () { int a[2][3] = { {20, 30, 10}, {60, 80, 90}}; int row, col; for(row = 0; row < 2; ++row) { for(col = 0; col < 3; col++) coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.