Function returns 0
return 0 c++
c++ return 0 vs return 1
the return 0 statement in main function indicates
return 0 in python
return 0 in java
return 0 and return
return 0 or 1 in c
I am writing a file import procedure. I have my column numbers mapped between the two files as a function
I pass in a variable called c which is the column on the import file, i then use case select in a function to output a different variable name with the mapped column numbers (which I am probably doing incorrectly
The case select works in that it stops at the correct case, passes over the cNew = x and then jumps to the end of the function
The issue I am having is that the new variable always returns 0. Variables and function are dimmed as integers
For c = 2 To 19 cNew = cMapped(c) MsgBox (cNew) Next c Function cMapped(c As Integer) As Long Select Case c Case Is = 1 cNew = 1 Case Is = 2 cNew = 3 Case Is = 3 cNew = 2 Case Is = 4 cNew = 7 Case Is = 5 cNew = 5 Case Is = 6 cNew = 16 Case Is = 7 cNew = 19 Case Is = 8 cNew = 21 Case Is = 9 cNew = 27 Case Is = 10 cNew = 30 Case Is = 11 cNew = 6 Case Is = 12 cNew = 11 Case Is = 13 cNew = 10 Case Is = 14 cNew = 32 Case Is = 15 cNew = 28 Case Is = 16 cNew = 33 Case Is = 17 cNew = 99 Case Is = 18 cNew = 50 Case Is = 19 cNew = 8 End Select End Function
Please try this one. You have to return the value this way. And I think
select looks this way in VBA.
Function cMapped(c As Integer) As Long Select Case c Case 1: cNew = 1 Case 2: cNew = 3 End Select cMapped = cNew End Function
So what does "return 0" actually mean?, return is not a necessary thing in main function. Its only used if you start your body with int main(). Then you have to write return 0; at the end. If you use void Whenever they type a simple formula in their spreadsheet, the value keeps returning a 0. When you type something like 10/2 the value returns as 5. Once the = sign is used (=10/2), the value is 0. This also happens when we try to reference other cells (i.e. =k12/1500 will also return a value of 0.)
Select Case c Case 1 cNew = 1 Case 2 cNew = 2 ... return cNew ...
Does this work better?
as answered by user10798192 and Michael Puckett II I was quite obviously not returning anything properly
Here was the adjusted code;
For c = 2 To 19 cNew = cMapped(c) MsgBox (cNew) Next c
And the amended function
Function cMapped(c As Integer) As Long Select Case c Case Is = 1 cMapped = 1 Case Is = 2 cMapped = 3 Case Is = 3 cMapped = 2 Case Is = 4 cMapped = 7 Case Is = 5 cMapped = 5 Case Is = 6 cMapped = 16 Case Is = 7 cMapped = 19 Case Is = 8 cMapped = 21 Case Is = 9 cMapped = 27 Case Is = 10 cMapped = 30 Case Is = 11 cMapped = 6 Case Is = 12 cMapped = 11 Case Is = 13 cMapped = 10 Case Is = 14 cMapped = 32 Case Is = 15 cMapped = 28 Case Is = 16 cMapped = 33 Case Is = 17 cMapped = 99 Case Is = 18 cMapped = 50 Case Is = 19 cMapped = 8 End Select End Function
C166: RETURN(0) IN A VOID FUNCTION, which means "main function should return integer data type" if main is declared like "void main", then there's no need of return 0. The Excel HOUR function returns the hour component of a time as a number between 0-23. For example, with a time of 9:30 AM, HOUR will return 9. You can use the HOUR function to extract the hour into a cell, or feed the result into another formula, like the TIME function.
Why return 0? - C++ Forum, 0, return values can be marked as nullable by prefixing the type name with a question mark (?). This signifies that the function returns either the specified type or I have been struggling with the SUMIFS function. I have a table of credit card charges that I am trying to use to input into a budget spreadsheet. I want the sum of charges that are in a certain category (Transportation, Shopping, Groceries, etc.) and a certain date (I've formatted the date to be "Aug-16" so that I can enter the it as a text condition, because I couldn't figure out how to
Returning values - Manual, You can take for example |x|+x2. You can construct similar examples. On most operating systems returning 0 is a success status like saying "The program worked fine". In C++ it is optional to type " return 0; " at the end of the main function and the compiler includes it automatically. In stdlib.h the macros EXIT_SUCCESS and EXIT_FAILURE are defined like this : Hide Copy Code.
Function that returns 0 for all negative values, This is because there is a full stop "." and not a comma "," to represent the decimal part of the number. A much faster way of fixing this is to use the find function (ctrl The int value that main returns is usually the value that will be passed back to the operating system. 0 traditionally indicates that the program was successful. You don't have to return 0 explicitly, because that'll happen automatically when main terminates.
- oh just to add I have set the function as long, as integer and without an as statement with no avail. If I don't set it at all rather than getting 0 I get "empty"
- You're not returning anything in your function. Instead of assigning cNew =... you should be returning that value.
- either put
cMapped = cnewat the bottom just before end function or change all of the cnew to cMapped.
- Thank you both. Amended cNew to cMapped as suggested and worked as expected. Can't believe out of all the things I tried that was not one of them. How do i flag comments as correct / useful?
- Thank you for taking the time to respond, I have not tested this but as the one above worked I would assume this would too.