gaza165 Posted November 23, 2008 Share Posted November 23, 2008 Hi Guys, I know this is a forum for PHP and I know this might not be replied to but i am having a problem with another language and i have been gaining knowledge from you guys for ages and i know how quickly everyone responds. I am programming in Processing 1.0 Beta for my Uni and they have asked me to do a simple problem. Its a simple method that outputs numberts from an array... The error i am getting is "This method must return a result of type int".... where am i going wrong?? // Declare my Global Variables int i; String OutPutLine = ""; PFont font; String[] Strs; int Size; int[] Nums; int Sum; //run the first method void setup() { font = loadFont("CourierNewPS-BoldMT-24.vlw"); textFont(font); background(255, 255, 0); fill(0, 0, 0); int[] Nums = { 90, 150, 30 }; } //run my created method int Sort(int[] Nums) { for (i = 0; i < 3; i++) { return Nums[i]; } } Link to comment https://forums.phpfreaks.com/topic/133892-this-will-seem-very-strange-but-i-trust-you/ Share on other sites More sharing options...
Mchl Posted November 23, 2008 Share Posted November 23, 2008 This might not be it, but: for (i = 0; i < 3; i++) { return Nums[i]; } In all languages I know, function can only return a value once, so running return in a loop is a nonsense. Link to comment https://forums.phpfreaks.com/topic/133892-this-will-seem-very-strange-but-i-trust-you/#findComment-696989 Share on other sites More sharing options...
corbin Posted November 23, 2008 Share Posted November 23, 2008 What language is this? Looks like C/C++ but could easily be something else. Why not just pass by reference and not have to worry about a return? IE: void someFunction(int[] &var) { for(int i = 0; i < 3; ++i) { var[i] = i; } } That is probably the most pointless method I've ever seen in my life though x.x. Link to comment https://forums.phpfreaks.com/topic/133892-this-will-seem-very-strange-but-i-trust-you/#findComment-697061 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.