FAQ Database Discussion Community


Return a pointer to array from a function in C++?

c++,arrays,function,pointers,return
I am a beginning programmer and I have a question about a function that returns a pointer to array of doubles in C++. The function takes two arrays and adds up each element, like in a sum of vectors. I think the correct way to do is.... double *myfunction(double *x,...

C++ operator overloading >= with 2 different returns

c++,return,operator-overloading
I've got a class which looks like this: class Player { friend bool operator>=(Player &pl1, Player &pl2) { return true; }; private: int nr, height, weight; } A player has a number, height and weight. Now I'd like to know if Player1 is bigger and/or heavier than Player2. After this...

Getting an Array from Return statement, deduce a string from that

sql,ruby-on-rails,arrays,ruby,return
I have a 'Case' conditional code snippet wherein I am returning two objects. The psuedocode is - case name when 'a' object1 = - SQL Logic - when 'b' object1 = - SQL Logic - when 'c' object2 = - SQL Logic - when 'd' object2 = - SQL Logic...

Best practice for returning in PHP function/method

php,function,methods,return,code-standards
I am refactoring an extensive codebase overtime. In the long run we are going to develop the whole system in classes but in the mean time I am using the opportunity to refine my PHP skills and improve some of the legacy code we use across several hundred websites. I...

inlining when function body has no return statement

c,return,inline
I read that compiler may not perform inlining when "return" statement does not exist in function body and also in the case where return type is other than void. If it's like inlining cannot happen with functions that return anything other than void, why it needed a "return" statement for...

Can someone please explain what “var result=1” is doing in this function?

javascript,return
Can anyone please explain, in plain English, what the "result=1;" is actually doing here? I know the function doesn't work without it and that even changing it to 0 breaks it, but I don't understand why. var power = function(base, exponent) { var result = 1; for (var count =...

Angularjs .factory method return

angularjs,methods,return,factory
I have been able to get this .factory to work by adding a "return" in front of both the Restangular.all statement and the response. My question is why is it needed there? Why can't I just return the response? app.controller('MainController', ['GetIndexesFromES', '$scope', function(GetIndexesFromES, $scope) { $scope.indices = GetIndexesFromES.getUniqueIndexIDs(); console.log($scope.indices); }]);...

I don't understand function return in javascript

javascript,function,return
Can anyone explain why javascript return statement is used in function? when and why we should use it? Please help me....

How to return 2 Strings in one method: String example(String firstName, String secondName)

java,string,methods,return
Public class Example1 { String fullname(String firstName, String secondName) { return firstName,secondName; //return fullname(firstName,secondName); doesn't work either :( } public static void main(String[] args) { Example1 myname=new Example(); System.out.println(myname.fullname("John", "Wick"); } } I got an error though, when I run my program. Can you help me out please guys? thanks...

Is it possible to return multiple items in my methods?

java,return,time-complexity
I have written three methods of different Big-O complexities. Is there a way to return multiple values in my method without affecting the complexity? Thanks in advance! public static double Nsquare(double[] ar){ double max=0, difference=0; double maxelement=0, minelement=0 ; for (int i=0; i<ar.length;++i){ for (int j=0; j<ar.length;++j){ difference=Math.abs(ar[i]-ar[j]); if (difference>max){...

Java - multiple return statements - first one not returning?

java,android,debugging,return
I'm toying around with some Android programming, and was in the process of writing a couple methods to open and close a file. Well, I wanted to do some basic checks on the file and return true if the conditions were satisfied, or return false if it reaches the end...

I need to find the longest word in a sentence using JS

javascript,html,count,return
I am having trouble getting my JS to return the longest word when I click on the button. I am not sure what in my JS code I am missing or have put incorrectly, but when I type in three words nothing is given back to me. I have pasted...

C++ returns objects by value

c++,function,return
The topic is pretty much in the title of the question. I saw this in Meyrses book "Effective C++": the fact that C++ returns objects by value What does that mean and how the C++ standard supports that message? For instanance, say that we have something like this: int foo()...

Return statement not working python 3

python,return
The idea of this code is, the user presses the first button and enters what they want, then they press the second button and it prints it out. Can someone please tell me why my return statement is not working? It says that 'variable' is not defined. Thanks in advance...

Php returning text between ?>

php,return
How can I return text between ?> and <?? For example: <?php function generateCode(){ return ?> TEXT HERE <? } ?> For what I've seen it just prints it on the screen. Is there any way to return that text?...

How to return multiple values without using Collections?

java,string,methods,collections,return
I am using textbook Murach's java programming, and in one of the exercises, it is asking me to do the following: add this method (given by the book): private static String displayMultiple(Displayable d, int count) write the code for this method so it returns a String that contains the Displayable...

return statement of function is not working as expected

php,function,return
I have 4 functions in my php script, which will access ascending order, at the last function i want to return a value, but the assignment isn't working. My php script: function fourth_f($var){ $var = $var + 1; return $var; //this will make the $var = 6 and return to...

Return statement for a string array giving strange result

java,arrays,string,return,system.out
I am creating a String array and using System.out.println to print the values in the array. All good and works as expected, returning [South Africa, England] but the code won't compile unless I include a return statement, but the return statement just dumps out a load of garbage "[Ljava.lang.String;@85bdf6". Is...

variable obj might not have been initialized

java,variables,object,return
While attempting an exercise, I got the following error: variable obj might not have been initialized The code: import java.io.*; public class Ex7 { public static NationalMessage nationalMessage(String fName){ NationalMessage obj; try{ BufferedReader scan = new BufferedReader(new FileReader(fName)); String currentline = scan.readLine(); while(currentline != null){ String[] lines = currentline.split(" ");...

Passing a return from one function to another function that already has set parameters?

node.js,function,return,processing,osc
Edit: I know JS is asynchronous, I have looked over the How to Return thread. The issue I'm having is that going from "foo" examples to something specific = I'm not quite sure where to re-format this. Also here is some context: https://github.com/sharkwheels/beanballs/blob/master/bean-to-osc-two.js I have a question about returns in...

Returning values from nested functions - JavaScript [duplicate]

javascript,google-maps,return,nested-function
This question already has an answer here: How to return the response from an asynchronous call? 7 answers I'm having some trouble returning the latLng value for the following function. function getUserPosition() { var latLng; if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( function (position) { latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); // #1...

Why can't I return this vector of vectors?

c++,vector,reference,return
I have a class that declares a vector of vectors of type char as the following and contains a method to read half of it and return the resulting vector. class Mapa { private: vector<vector<char> > vec; public: //Constructor Mapa():vec(0,vector<char>(0)){}; Mapa(int row, int col):vec(row, vector<char>(col)){}; virtual ~Mapa(){}; } const Mapa&...

Trying to execute a assembler bytestream as a C native function

c,segmentation-fault,return,memory-address
I was trying to overwrite the return address of main() with the address of the shellcode that I wrote in assembly. My assembly program : ExitShell.asm SECTION .text global _start _start: jmp short shellOffset Shellcode: pop esi lea ecx, [esi] mov dl, 12 mov bl, 1 mov al, 4 int...

Why does returning in Interactive Python print to sys.stdout?

python,return,stdout,python-idle
I ran into something different today. Consider this simple function: def hi(): return 'hi' If I call it in a Python shell, >>> hi() 'hi' >>> print hi() hi It prints out the 'returned' value, even if it's just the repr. This felt odd to me, how could returning be...

How to return a value of indeterminate type from a switch statement from a method

c#,switch-statement,return,return-value
I have the following switch statement: switch (SomeType) { case SomeType.A: var data = (Type_1)SomeType.Data; case SomeType.B: var data = (Type_2)SomeType.Data; case SomeType.C: var data = (Type_3) SomeType.Data; case SomeType.D: var data = (Type_4) SomeType.Data; case SomeType.E: var data = (Type_5) SomeType.Data; case SomeType.F: var data = (Type_6) SomeType.Data; }...

How to return multiple results in a php function

php,function,foreach,return
I have the following function that aims to fetch all credits from an artist for a particular song using the ID from the url ($id), and a foreach statement that displays the information on the Web page. At the moment it's displaying the artist names fine, but the IDs aren't...

C# Enter Timestamp at Enter in Richtexbox

c#,visual-studio,timestamp,return,richtextbox
I am trying to add a timestamp into a richtextbox everytime i hit "enter" on keyboard. The code below partially works, however at Enter a new line is added below my Timestamp. I then have to Backspace to type next to my timestamp. Any suggestions please send. private void richTextBox2_KeyDown(object...

Want to `return` more than once

javascript,three.js,return
I want to return multiple lines (one line each time the for-loop goes around), but it only returns the first line. I tried to write a function just to return the line, but I got errors with it because I don't know where to put it. What's a good way...

What happens with return value?

c++,pointers,return
So I have 2 classes for this example: E, which prints a message when it is destroyed + can store integer value T, which stores instance of E and can return it through a method Code: class E { public: E(); ~E(); int test; }; E::E(){} E::~E() { std::cout <<...

Returning a formatted string does not working properly

java,format,return,duplicates,string.format
I have created a dupe-check that makes sure that newly created usernames are unique. It looks like this: String p1 = <code>; //First 3 chars in first name String p2 = <code>; //First 3 chars in last name int p3 = 1; //Unique identifier. boolean dupeCheck; do { dupeCheck =...

What is the difference between these two methods for checking if a number is a prime?

java,return
I wrote a method for checking if a number is a prime: static boolean isPrime(int x) { for (int i = 2; i <= Math.sqrt(x); i++) { if (x % i == 0) return false; } return true; } In a collection of exercises we're learning from, the solution is:...

Can long int be returned by a function in c?

c,function,return
Suppose we want to return a long integer by a function. How to do it? Is it valid? long int function() { long int b; b=1000000000; return b; } ...

char * disappears if I don't print it?

c,string,return
I have a very odd problem here. I basically have a function which takes in a char* and it splits the string and returns the substring. My problem is if I print length of the char* THEN return it then the value remains but if I don't call the function...

JAVA adding total

java,return,totals
I would like to have this function used inside of another function. what this "addTotal" function does is it returns the total balance of each bankAccount that a certain client has. I know by inserting the "return total;" statement, it only gets the first bankAccount balance only. Any suggestion on...

Unable to return correct value of a variable in a recursive function

c,function,recursion,return,factorial
I am making following program to find factorial of a given number recursively. #include<stdio.h> int fact1=1; int recursion(int x) { if(x==0) { return fact1; } fact1=fact1*x; x--; recursion(x); } int main() { printf("%d",recursion(5)); return (0); } Problem : The problem is that whenever I run this program it always gives...

Assigning (or tieing in) function results back to original data in pandas

python,pandas,return,def
I am struggling with extracting the regression coefficients once I complete the function call np.polyfit (actual code below). I am able to get a display of each coefficient but am unsure how to actually extract them for future use with the original data. df=pd.read_csv('2_skews.csv') Here is a head() of the...

when a method should return a value java

java,eclipse,return
I am a new user for java and I am a little confused on whether a method should return a value or not in java for example I wrote this simple method public static void increase_user() { int number=3; if(number<10) user++; } public static void main(String[] args) { int user=10;...

Java “add return statement” error

java,return,unreachable-statement
public class1 foo ( class1 t) { if ( object == null ) return t; else foo(t.childObject); } Java keeps telling me that there is no return statement. I can understand what is wrong here, but I cannot fix it without removing the recursion, which I really need. Is there...

python 3.4.3 basic return issue

python,return
Below is the basic code from a 2.x tutorial I'm looking at while I'm starting off on 3.4.3: Below is the function def hello(): print ("hello") return 1234 And here is the function being used hello() The tutorial states that the program should print "Hello" on the top line, and...

Remove element after returning a value from it

jquery,return
I'm trying to create an element, set a value to it, and, return that value and then remove the element. Obviously the last part doesn't work, because return ends the function. How would I go about this? function myFunc(a) { var d = $("<div>"); d.css("color",a).appendTo("body"); return d.css("color"); // Everything below...

python input check function not being called properly

python,return,global-variables,try-catch,raw-input
I'm working on a very simple temperature converter in Python (just for practice), and am struggling with some of the UX components. I'd like to have checks in place to continue prompting for variable input when invalid entries are made. My full code is below: o_temp = '' def temp_input(o_temp):...

How can I use a non-static (dynamic instance) object as return for a static method in Java? [closed]

java,static,return
I have searched through stackoverflow as well as a few other sites and sadly have not found this question asked, let alone answered. Maybe my approach is best attempted another way? I am new to Java; this should be a really easy answer I would think. The issue: I have...

Read external file match specific string in first column and return respective string of second column in php

php,string,return,matching,vlookup
I have two text files, csvurl.txt and tickerMaster.txt tickerMaster.txt H0001 Remarks: No "H0003" in tickerMaster.txt and the number are not in sequence csvurl.txt H0001, URL1 H0003, URL3 I would like to read the entries in tickerMaster.txt one by one, say H0001, H0003... and createURL by matching the data in csvurl.txt....

Android: How to return huge byte array as activity's result?

android,android-intent,camera,return,onactivityresult
private void returnImage(byte[] array) { Intent intent = new Intent(); intent.putExtra(RETURNING_MESSAGE, array); setResult(RESULT_OK, intent); finish(); } I get that byte array by Camera via these callbacks @Override public void onClick(View v) { mCamera.takePicture(null, null, new Camera.PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { mCamera.release(); returnImage(data); } }); }...

Animated/timed text with JavaScript return

javascript,return
I have the following code: function list() { return "blob1<br>blob2<br>blob3"; } When this code is run, it directly displays the whole text in return on the call of the function. Is there a way to make it display blob1, then wait for 0.5 seconds, then display blob2, then after 0.5...

python functions veusz object

python,function,return
Hi I'm trying to put together some functions to perform common tasks using Veusz' object oriented command line (https://github.com/jeremysanders/veusz/wiki/EmbeddingPython). VszPlot(x,y) should create an initial plot on an embedded window of the lists x against y. I then want to have a second function AddPlot(x,y) which will add the new data...

NGINX - Return vs Rewrite

redirect,nginx,return,rewrite
I use NGINX in my dedicated server. I've a question, with the return and rewrite 301. Rewrite 301: rewrite ^ http://xxx.xxxxx.net/xx-xxx/$request_uri? permanent; Return 301: location ~ redirect-this/?$ { return 301 http://xxx.xxxxx.net/xx-xxx/redirect-this$1; } All redirect correctly to the URL requested. But.. What is more effective method, to make an 301 redirect?...

How would I access this specific part of a JSON?

json,location,return
Okay so I have a JSON that is returned from a POST function, but the problem is that the length of the JSON changes, the values are not all in set locations. For example here is one return: http://pastebin.com/dPt4fSgN And here is another return: http://pastebin.com/iALUPBTn Sorry that you have to...

Remote Job execution with non terminating Return

powershell,return,powershell-remoting
I have a script that I am running both remotely and locally in different situations. In the remote situations I would like to return some additional job information. However, the script also needs to complete with a Restart, LogOff, etc. However, if I Return $Results, no code that follows is...

Return data from async function [duplicate]

javascript,node.js,asynchronous,data,return
This question already has an answer here: How to return the response from an asynchronous call? 7 answers Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference 3 answers I've been reading a lot about callbacks, but still don't get it......

Java: Inheriting method with return type

java,inheritance,return
The Class3 class extends to Class1 class. In Class3, the method should return the total of the bonus and the salary and Class1 inherits from Class3 and displays the total and calculates the yearly salary by multiplying the total by 12. The problem is that the output which is I...

Return type of a constructor in c++

c++,constructor,return,return-type
I am learning c++, and I came across following code segment: class X { int i; public: X(int ii = 0); void modify(); }; X::X(int ii) { i = ii; } void X::modify() { i++; } X f5() { return X(); } const X f6() { return X(); } void...

sweetAlert preventDefault and return true

jquery,return,preventdefault,sweetalert
I tried sweeAlert plugin, which works perfectly, but I cant figure out how to do default stuff after confirm. $(document).ready(function () { function handleDelete(e){ e.preventDefault(); swal({ title: "Are you sure?", text: "You will not be able to recover the delaer again!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Yes, delete!",...

Tic Tac Toe Game: How to loop it?

c++,loops,return
Currently working on a Tic Tac Toe Game ran across a problem with looping the function after a player has won. I tried using, exit(1); however that just exits out of the entire program, and doesn't allow a loop. What I want is to exit out of the game and...

JS why is other code ignored and only return executed

javascript,return
I got this code which always gave the same result: var number = 0; function a(){ number++; //outside return function return function(){ return number; }; } var b = a(); //outside loop for(i=0;i<10;i++){ console.log("loop: "+(i+1)+" :"+b()); } I found this solution (1): var number = 0; function a(){ number++; //outside...

Replacing roman numerals with numbers from file- Python- type error

python,file,return
I am attempting to read a file, then for each roman numeral in the file, replace it with the correct numerical value (only for numerals 1-7) then save the file (with all the text and only the numbers changed) to a new file. I have printed what I have for...

Function that calls itself returns only first result of its call

python,return,call
I have a string s="expences > drinks" that is sent to a function. Inside that function I am supposed to add new values using raw_input() till I input an empty string. Each one of these inputs should be added to the initial string. In the case of an empty string,...

Recursive function in PHP function : how to prevent return value?

php,function,recursion,return,return-value
I am working on an API to get data, just like the other standard API, it limit on the return numbers of item , e.g. each page return only 1 item in my case. So , I have to get the total_count, page_size (it is 1 at my case), and...

good practises null object return [closed]

c#,object,null,return
I have a question about c# programming language, when a method returns an object, and for example I'm forced to return null, which is not clean code, what is the best practise to handle this? I dont want to return null.

TypeError: 'NoneType' object is not iterable when calling keys function

function,return,typeerror,iterable,nonetype
I am getting the error xShift, yShift = Manager.movementKeys(self, xShift, yShift) TypeError: 'NoneType' object is not iterable when I run my code and I can't figure out why. I don't shouldn't be getting any returns as None and none of my arguments are None. I apologize for any indentation errors....

c# Pass a multi-line string to a function and return an array

c#,arrays,string,textbox,return
I'm new to C# programming and I'm trying to use good code practices. I know it is poor coding to use global variables in my example below, but I'm having a hard time figuring this out. So,I'm trying to accomplish two things with this question. first of all, I am...

mt_rand() returns unexpected output

php,string,function,return
I am working with my ad system of my site and having trouble with this. <?php function bdads($size, $company) { if($company == 'nufa') { if ($size == '300'){ echo 'n300'; } if ($size == '160'){ echo 'n160'; } if ($size == '728'){ echo 'n728'; } if ($size == '700'){ echo...

Returning a pointer which is a locally declared wchar_t

c,static,scope,return
I've read a lot of questions about returning pointers in C, but am still confused with the issue of scope. The following code works because of the call to malloc, and one possible output might end up being Wide string: StackOverflow. #include <stdlib.h> #include <string.h> #include <stdio.h> #include <wchar.h> static...

SDL window closes on startup and returns 0

c++,return,sdl,exit
The window closes as soon as i start the program. this is the main function: int main(int argc, char* argv[]) { if (!init()) { printf("Could not initialize!"); } else { bool quit = false; SDL_Event ev; while(!quit) { while(SDL_PollEvent(&ev)) { if(ev.type = SDL_QUIT) { quit = true; } } }...

Am I oversimplifying returns?

java,arrays,return
Basically I'm doing the old driver exam program for a uni course and I've drafted out the whole class. When I try to compile it, if working in command prompt, I get the error: missing return statement and in Eclipse: This method must return a result of type int` pertaining...

Scala: “explicit return” required?

java,scala,boolean,return
I thought in Scala I don't need to explicit put "return" in the return statement. So I have the following code: def checkSimple(str1: String, str2: String): Boolean = { if (str1 > str2) { println("str1 > str2") true } println("str1 <= str2") false } if I ran my above code...

php return statement in if statement

php,if-statement,return
Maybee my question is somehow elementary or stupid, however i need to verify this. I have a php function "functionA" which is repeatidely called in a for loop: ... for($j=0; $j<$n_samples;$j++) { if($type=='triband') { functionA($arg1,$arg2); } } ... and my functionA: ... functionA($arg1,$arg2) { $wide_avg_txon = substr($bit_sequence,0,1); if($wide_avg_txon==0) { echo...

Why my function return an array with only one element?

javascript,arrays,return
I am writing a function that will return an array with prime numbers. The function should return an array with n elements. (n is a parameter) But it returns only one element. Why? My codes: function findPrimes(n) { var arr = []; var currIndex = 0; var sqrtNum; var ceiledNum;...

Python: return statement still returns none from function

python,function,return
I've looked at all of the other "Returns none" questions on here and none of them seem to solve my problem. rates = [] for date in unformatted_returns: # Please ignore undefined variables, it is redundant in this context if date[0] >= cutoff_date: date_i = unformatted_returns.index(date) r = date_initialize(date[0], date_i)...

How do I return a value from a second function in PHP?

php,function,return,value
I'm a green green newbie trying to write a simple program in PHP. I use an HTML form to ask a "diner" to select an entree, which sends the choice to a PHP program.The PHP program is supposed to echo the entree choice, suggest a drink to the diner, and...

APL return value of a function

return,return-value,apl
I want to know how to return a value after my function finishes running. I have, for example: FUNCTION X ? X ⍴ 10 //This means, generate X random numbers (X is the function's argument) within the range 1-10. I just want to know how I can return the value...

c++ function returning template type checking

c++,templates,types,return,token
I have read through some questions here and cant find anything specific to my problem so I don't know if I am doing it completely wrong or just am missing something specific. What I am trying to do is tokenize some data and input that into a function and return...

is return main(); a valid syntax?

c,function,return,language-lawyer,return-type
I found some interesting code lines: #include <stdio.h> int main() { printf("Hi there"); return main(); } It compiles ok (VS2013) and ends up in stackoverflow error because of the recursive call to main(). I didn't know that the return statement accepts any parameter that can be evaluated to the expected...

How can i change action of the button “return” on the keyboard on Xcode?

ios,text,keyboard,return,action
i need to change the text of the button "return" on my keyboard,and i even need to change its action. The action should be a new paragraph. Can you help me?

sql server function does not allow return statement

sql-server,function,return
I am trying to create a function in sql server but it keeps telling me : A RETURN statement with a return value cannot be used in this context. I have many other functions and they all end with return @variable. So I must be doing something wrong here and...

Tcl return vs. last evaluated in proc - internals

return,tcl,proc
When I write a proc in Tcl, which return value is actually the result of another proc I can do either of the following (see implicit example): proc foo args { ... ... bar $var1 } Or I could do (see explicit example): proc foo args { ... ... return...

Matlab Reintroduction of AR and GARCH processes

matlab,for-loop,return,time-series,volatility
I am trying reintroduce autocorrelation and heteroskedasticity to my simulated residuals. My simulated (standardized) residuals have the dimension (horizon, nTrials, nIndices). In order to calculate today's mean / variance (i.e. t), I need to use the last periods mean /variance (i.e. t-1) as an input. This is where I am...

How to Supress implicit return from a closure with Void return type in Swift

swift,return,closures,implicit,completion-block
lets consider we have a closure like: (used as completionHandler) func doSomething (completionHandler : (done : Bool)->Void )->Void { ... completionHandler(true) } now if we want to do something like that : doSomething({ (done : Bool)-> Void var data : NSDictionary = NSDictionary() data.setValue("data1", forKey: "data1") // 1 data.setValue("data2", forKey:...

Return pointer undefined even though it should be

c++,pointers,return,undefined
I have something like this. Why is lastItem undefined? Menu* CreateItem() { Menu* menuPointer = new Menu; //initialize values return menuPointer; } void AnotherFunction() { Menu* lastItem = CreateItem(); } Thanks a lot! EDIT: I just figured it out, but I don't really understand why that wasn't working. The more...

Return json array from client to spring controller

json,spring,return
I need to send data from the client html back to the spring controller. I have a controller which generates a Json array whichh I sent via ajax to the html side when requested. That functions well. The Problem is I need to send the Json array back to another...

Golang, how to return in func FROM another func?

go,return,func
I want to end execution in parent func apiEndpoint() upon calling/exiting in a child func apiResponse() func apiEndpoint() { if false { apiResponse("error") // I want apiResponse() call to return (end execution) in parent func // so next apiResponse("all good") wont be executed } apiResponse("all good") } func apiResponse(message string)...

global variable returns null when sent to list

php,variables,null,return,global
I'm currently working with these two parts of code. One is for receiving the data and one for displaying it in a list, but for some reason the variable $emp_name always returns null when I'm trying to display it in the second part. The idea is to search an employee...

JavaScript: How do I return two values from a function and call those two variables in another function?

javascript,function,parsing,return
JavaScript: function getValue(){ var num1 = document.getElementById("firstNum").value; var num2 = document.getElementById("secondNum").value; return (num1, num2); } function add(){ getValue(); var result = parseFloat(num1) + parseFloat(num2); return result; } What I'm creating is a calculator that gets the values from input boxes. What I'm having trouble with is how am I supposed...

Prolog- Returning elements from facts

prolog,return,element,fact
i encounter a problem with facts. Let's say i got 3 facts and check(X) question. fact(a,b). fact(b,c). fact(a,d). check(X):- //some calculation with fact() How to make above question to return list of elements for given X from all facts? For instance: check(a) would give result b and d. So i...

What is different between return 1 and return 0? And how backtracking work in given code?

c,function,boolean,return,backtracking
int solve(int a[]) { int index,i; index=find_index(a); if(index==101) { return 1; } if(index!=101) { for(i=1;i<=9;i++) { if(cheak_coll(a,i,index)==1 && cheak_grid(a,i,index)==1 && cheak_row(a,i,index)==1) { a[index]=i; if(solve(a)) { return 1; } a[index]=0; } } } else { return 1; } return 0; } In given example what is different between return 1 and...

AS3 Custom DialogBox: How to send pushed Buttons label to Main.fla

actionscript-3,class,flash,return
I made my own AS3-DialogBox-class. It has 2 Buttons ("Yes" and "No") Within the class there is a listener that starts a function when one of the Buttons was pushed. And within this listener-function I can get and trace the Buttons label ("Yes" or "No") by calling event.currentTarget.MyButtonTextfield.text. So my...

When returning an object, I can't simply use {} after class name

c++,return
Taking this educational code about nested classes as an example: class enclose { struct nested { // private member void g() {} }; public: static nested f() { return nested{}; } }; int main() { //enclose::nested n1 = e.f(); // error: 'nested' is private enclose::f().g(); // OK: does not name...

Please explain this output of the code

c,function,return,printf,scanf
#include<stdio.h> int GetPositiveInt(void); int main(void) { int num = GetPositiveInt(); printf("%d",num); return 0; } int GetPositiveInt(void) { int n; do { printf("Enter a positive number : "); scanf("%d",&n); }while(n<=0); } The output is the value of n but I don't know how it is returned to num. Does scanf() and...

Difference in a way of writing a void function return [duplicate]

c++,return,void
This question already has an answer here: Returning From a Void Function in C++ 7 answers Here's a code snippet I found here void App::onSave() { if (filename.isEmpty()) return onSaveAs(); //do saving here } void App::onSaveAs() { QString f = QFileDialog::getSaveFileName(NULL, "Save as", "", "*.sb"); if (!f.isEmpty()) { //filename...

VBA Return Carriage and Fill Code

excel,vba,excel-vba,return,carriage-return
I'm really new to vba and would appreciate any assistance in the following problem I'm having. Problem description (in relation to diagram below): 1*) In c, I have managed to separate the return carriages, which leads to 2*) now that each return carriage has it's own row, I need column...

Syntax error on return

python,return,syntax-error
There's the following code I'm trying to get running that returns a syntax error on line 10's "return". I also tried removing that part (making the code of course not working) and it returned an error on the print shortly after, so I'm mostly sure there's a problem there that...

Return new something in function returning a shared_ptr

c++,constructor,return,shared-ptr,implicit-conversion
I have a function that returns a shared_ptr to a const object. Returning a shared_ptr constructed from a pointer returned by operator new works, but returning that pointer directly causes compilation error : Error 3 error C2664: 'std::shared_ptr<_Ty>::shared_ptr(std::nullptr_t)' : cannot convert parameter 1 from 'script::float_data *' to 'std::nullptr_t' c:\xxx\value.cpp 59...

c++ : stop only last call of recursive function

c++,recursion,return
I have a function that a call recursively : void myFunction(int j, int N){ if(j == N) return; for(int i = j +1 ; i < N ; ++i){ myfunction(i); } } My problem is that the return will stop the full recursion (from the first calling node), but I...

When to use exit() over return? [duplicate]

c++,c,return,exit
This question already has an answer here: return statement vs exit() in main() 7 answers I was wondering when should I use exit() function over return statement. I can end the program with either of the following statements: exit(0); or return; Which one should I use and when? Is...

Missing return statement error with method that has a return in for loop

java,string,for-loop,return
I have a method that returns all the names of people in a LinkedList for a plane. However even though there is a return statement in the method, I'm still getting told there is a missing return statement. How can I work around this without putting another return statement in?...

Can a Python function return only the second of two values?

python,matlab,function,return
I have a Python function that returns multiple values. As an example for this question, consider the function below, which returns two values. def function(): ... return x, y I know this function can return both values x, y = function(). But is it possible for this function to only...

Return various amounts of values in symfony

php,arrays,symfony2,return
I have little problem, because I have no idea how to do one thing. I want to return on page sometimes 3 values, sometimes 5, sometimes n and I have no idea how to do it. Here is my code (controller): $result = count($countries); $tablica = array(); for ($i =...

Sharing values between methods

python,python-3.x,return,return-value
I thougth I knew how to use return in Python but something came up and i dont understand it. class Projet(object): def pathDirectory(self): pathDir= str(QFileDialog.getExistingDirectory(ui.pathTab1, 'Select Path','', QFileDialog.ShowDirsOnly)) return pathDir def goFunc(self, pathDir): # do function # HERE pathDir is a boolean and not a str with the path directory...

Gulp task runs much faster without 'return' statement - why is that?

build,return,task,gulp
Gulp task formed like this (without return) runs much faster: gulp.task('less', function () { gulp.src('./less/**/*.less') .pipe(less()) .pipe(gulp.dest('./destination')); }); than the same one with return: gulp.task('less', function () { return gulp.src('./less/**/*.less') .pipe(less()) .pipe(gulp.dest('./destination')); }); So, my question is what does Gulp task is supposed to return? Why is it so much...

Python: how to reference values in a def

python,reference,return
As a very basic example of what I want to do, I want to update the values 1 and 2, after running them through the example method. Like how you would use ref for Java. def example(value1, value2): value1 += 2 value2 += 4 value1 = 0 value2 = 0...