I didn't mean a new line, i meant a newline, as in '\n' or std::endl, just like Salem also suggested.
I didn't mean a new line, i meant a newline, as in '\n' or std::endl, just like Salem also suggested.
How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.
I just tried what jimblumberg told me to do but it doesn't work any more. Please could someone give me a piece of code that would help me understand because honestly, i still can't see how to make an array of 6 lines and 6 columns displayed filled with zero on the console, even if i try everytime applying the advices you give me
If someone would give me the simple code that displays an array of 6 lines and 6 columns filled with zero i would greatly appreciate it
This seems to work for me:
Code:#include <iostream> using namespace std; int main() { const int size = 26; int marray[size][size] = {{0}}; for(auto i : marray) { for(auto j = 0; j < size; ++j) cout << i[j] << " "; cout << endl; } return 0; }
Jim
Last edited by jimblumberg; 03-09-2013 at 03:34 PM.
The problem has now been resolved !! Thank you everybody for your help !
I just had to add ain my outter loop of my function printOutArray as Neo1 told me, but i have to tell my error to all the readers who are also beginning in programming (in C++) like me : i didn't want to put acout << ENDL.in my outter loop of my function printOutArray because in my opinion cout<< endl equals "go to the next line", and yet putting an endl is just like sending a character which indicates the CONSOLE to go to the next line (on the console), HOWEVER it DOES NOT mean that you increment the line, and i wrongly thought that it was like incrementing the line (so why increment the line twice at each way in the loop?). This was a wrong way of thinking.cout << ENDL.
Here is my code that now works, and makes an array of 6 lines and 6 columns :
Code:#include <iostream>#include <iomanip> #include <cstdlib> using namespace std; void initArray(float largeArray[6][6]){ for (int x=0; x < 6; x++){ for (int y=0; y<6; y++){ largeArray[x][y] = 0; } } } float printOutArray(float largeArray[6][6]){ for (int x = 0; x < 6; x++){ for (int y = 0; y < 6; y++){ cout << largeArray [x] [y]<<'\t'; } cout << endl; } return largeArray[6][6]; } int main() { float largeArray [6][6]; initArray(largeArray); printOutArray(largeArray); }
Sorry i meant acout << endl ;
OK i don't have to return my array in this exemple, so is this code right ? (i deleted:return largeArray[6][6];
Moreover, can someone tell me if my indentation is good (or not)?Code:#include <iostream> #include <iomanip> #include <cstdlib> using namespace std; void initArray(float largeArray[6][6]){ for (int x=0; x < 6; x++){ for (int y=0; y<6; y++){ largeArray[x][y] = 0; } } } float printOutArray(float largeArray[6][6]){ for (int x = 0; x < 6; x++){ for (int y = 0; y < 6; y++){ cout << largeArray [x] [y]<<'\t'; } cout << endl; } } int main() { float largeArray [6][6]; initArray(largeArray); printOutArray(largeArray); }
Thank you Elysia
If you are not going to return an array, this is fine.
Indentation is acceptable. Rule is that for every opening {, you use another indentation level (+ n spaces or a tab, depending of your preferences). Keep it consistent.
EDIT: Missed the float return type in printOutArray...
In my opinion it could use some improvement. One of the biggest things you need to work on is being consistent. Look at the following snippet, and notice how in the first function you have your brace on the same line as the definition, yet main() has the opening brace on a separate line. Either is acceptable, but be consistent. Also consistent placement of where you place the ending brace in your control structures. I normally place the ending brace at the same indent level as control statement.Moreover, can someone tell me if my indentation is good (or not)?
The only other issue is that your function is still wrong. You told the compiler you would be returning a float, but you aren't returning anything. If you don't want to return anything then the function should be defined as a "void", otherwise return the proper type of variable, never lie to the compiler.Code:float printOutArray(float largeArray[6][6]) { for (int x = 0; x < 6; x++) { for (int y = 0; y < 6; y++) { cout << largeArray [x] [y]<<'\t'; } cout << endl; } } int main() { float largeArray [6][6]; initArray(largeArray); printOutArray(largeArray); }
Jim
OK. Finally, the code with 0 errors is :
Code:#include <iostream>#include <iomanip> #include <cstdlib> using namespace std; void initArray(float largeArray[6][6]) { for (int x=0; x < 6; x++){ for (int y=0; y<6; y++){ largeArray[x][y] = 0; } } } void printOutArray(float largeArray[6][6]) { for (int x = 0; x < 6; x++){ for (int y = 0; y < 6; y++){ cout << largeArray [x] [y]<<'\t'; } cout << endl; } } int main() { float largeArray [6][6]; initArray(largeArray); printOutArray(largeArray); }