|
| reginat1 (9) | |
| I am writing a code that draws 4 triangles. I keep geeting code C2562 'Triangles::drawTriangles' : 'void' function retruning a value. PLease help. I am using Visual C++ 2008 Express Edition SP1 // Member-function definitions for class Triangles that draws triangles. #include <iostream> using std::cout; using std::endl; // include definition of class Triangles from Triangles.h #include "Triangles.h" // function to draw triangles void Triangles::drawTriangles() { // Variable declarations (no other variables are needed) int row; // the row position int column; // the column position int space; // number of spaces to print // first triangle /*write a for header to interate column from 1 to 10 */ for (int column = 1; column <= 10; column++) { /*write a header ti interate column 1 to row*/ for (int column = 1; row <= 10; column++) cout << "*"; cout << endl; } //end for cout << endl; // second triangle /*write a for header to iterate row from 10 down to 1 */ for (int row = 10; row >=1; row++) { /*write a for header to iterate column from 1 to row */ for (int column = 1; row <=10; column++) cout << "*"; cout << endl; } // end for cout << endl; // third triangle /* write a for header to iterate row from 10 down to 1 */ for (int row = 10; row >=1; row--) { /*write a for header to iterate space from 10 down to one more than row */ for (int space =10; row >=1; space++) cout << "*"; cout << endl; } // end for cout << endl; // fourth triangle /*write a for header to iterate row from 10 down to 1 */ for (int row = 10; row >=1; row++) { /*write a header to iterate space from 1 to one less than row */ for (int space =1; row <=10; row--) cout << "*"; /* write a for header to iterate column from 10 down to row */ for (int column =10; row >=1; column++) cout << "*"; cout << endl; } // end for return 0; // program terminated successfully } // end function drawTriangles Error 1 error C2562: 'Triangles::drawTriangles' : 'void' function returning a value c:\documents and settings\regina\my documents\visual studio 2008\projects\project 5 program 4\project 5 program 4\tuckerr_assign5prog4_triangles.cpp 76 | |
| firedraco (2624) | |
Your function is delcared as returning void, i.e. nothing, but you are trying to return 0; at the end. | |
| bluezor (237) | |
return 0; // program terminated successfully Your triangle function is technically returning a value. To exit, you can use exit(0);, instead of returning a value. | |
| reginat1 (9) | |
| I tried the [exit 0] and got the following errors: Error 1 error C2143: syntax error : missing ';' before 'constant' c:\documents and settings\regina\my documents\visual studio 2008\projects\project 5 program 4\project 5 program 4\tuckerr_assign5prog4_triangles.cpp 76 Warning 2 warning C4551: function call missing argument list c:\documents and settings\regina\my documents\visual studio 2008\projects\project 5 program 4\project 5 program 4\tuckerr_assign5prog4_triangles.cpp 76 | |
| bluezor (237) | |
Are you missing a semi-colon after your exit(0);? | |
| reginat1 (9) | |
| I had the semi-colon after the 'exit 0' | |
| helios (6079) | |
No, not exit 0;. Literally, exit(0);. It's a function, not a syntactical construct.EDIT: Wait, I don't think a function called 'drawTriangles()' is supposed to actually kill the program. That's terrible advice, bluezor. | |
Last edited on | |
This topic is archived - New replies not allowed.
