I cant for my life figure out why this one is not working, cany anyone help me getting this code to run? :/ im getting about 10 errors so far #include "stdafx.h" #include <iostream> #include <ctime> using namespace std; int main(); int grid[3][3]; // grid int count = 1; for(int i = 0; i < 3; i++){ for(int n = 0; n < 3; n++){ if(i == 2 && n == 2) break; // dont give out a number to square 9 grid[i][n] = count; // give out a number to square 1-8 count++; { return 0; } } } Code (markup):
It helps if you copy the errors here, too... give us as much information as you have! A lot of us don't have quick access to a compiler but can look at errors and tell you what they mean.
these are my errors that i got. \nummerspel.cpp(15) : error C2059: syntax error : 'for' 1>c:\\nummerspel.cpp(15) : error C2143: syntax error : missing ')' before ';' 1>c:\\nummerspel.cpp(15) : error C2143: syntax error : missing ';' before '<' 1>c:\\nummerspel.cpp(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\\nummerspel.cpp(15) : error C2143: syntax error : missing ';' before '++' 1>c:\\nummerspel.cpp(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\\nummerspel.cpp(15) : error C2086: 'int i' : redefinition 1> c:\\nummerspel.cpp(15) : see declaration of 'i' 1>c:\\nummerspel.cpp(15) : error C2059: syntax error : ')' 1>c:\\nummerspel.cpp(15) : error C2143: syntax error : missing ';' before '{' 1>c:\\nummerspel.cpp(15) : error C2447: '{' : missing function header (old-style formal list?) 1>Build log was saved at "file://c:\nummerspel\Debug\BuildLog.htm" 1>nummerspel - 10 error(s), 0 warning(s)
Oh I think I see the problem... you're defining the main function as essentially empty by doing: int main(); instead, you mean: int main() { and then, naturally, another closing } at the end of the file. See if that helps.
al the other errors are gone, now im getting nummerspel.cpp(28) : fatal error C1075: end of file found before the left brace '{' at 'c:\\nummerspel.cpp(11)' was matched :/
Did you put in that last closing } at the end of the file? If you did, just work back through your file and make sure that you have matched all of your braces. Code that short shouldn't take very long at all to find the missing set.
now it's working! bellow is the correct code, however what's my problem now is that the code is supposed make a 3*3 grid and fill 8 of the panels with numbers and leave one empety. but when i run the program nothing appears in the CMD window at all doyou know why? #include "stdafx.h" #include <iostream> #include <ctime> using namespace std; int main() { int grid[3][3]; // grid int count = 1; for(int i = 0; i < 3; i++){ for(int n = 0; n < 3; n++){ if(i == 2 && n == 2) break; // dont give out a number to square 9 grid[i][n] = count; // give out a number to square 1-8 count++; { return 0; } } } } Code (markup):
Well the problem is that nowhere in that code do you even attempt to print anything... you're just populating an array. You need to printf (or cout) some numbers...
Go ahead now !! Error : Use of extra closing Braces. stdafx.h was of no use in this program so just commented !! //#include "stdafx.h" #include <iostream> #include <ctime> using namespace std; int main() { int grid[3][3]; // grid int count = 1; for(int i = 0; i < 3; i++){ for(int n = 0; n < 3; n++){ if(i == 2 && n == 2) break; // dont give out a number to square 9 grid[i][n] = count; // give out a number to square 1-8 count++; } } return 0; } Code (markup): Return don't need opening and closing braces. and Return statement was needed out of Loop.
nwm about my other post, now it prints! however, the number become 1,2,3,4,5,6,7,8, how can i make it print one endl per row ? #include "stdafx.h" #include <iostream> #include <ctime> using namespace std; int main() { int grid[3][3]; // grid int count = 1; for(int i = 0; i < 3; i++) { for(int n = 0; n < 3; n++){ if(i == 2 && n == 2) break; // dont give out a number to square 9 grid[i][n] = count; // give out a number to square 1-8 count++; cout << grid[i][n]; } } return 0; } Code (markup):
After your: cout << grid[n]; you should just be able to add something like: if (n == 2) { cout << endl; }