Skip to main content
13 events
when toggle format what by license comment
Aug 2, 2015 at 8:30 comment added jon.tre does anyone have any idea?
Aug 1, 2015 at 20:52 comment added jon.tre jharvard@appliance (~/Dropbox/pset3/find): ./find 42 haystack[0] = 40 haystack[1] = 41 haystack[2] = 42 haystack[3] = 43 haystack[4] = Found needle in haystack! jharvard@appliance (~/Dropbox/pset3/find): echo $? 0 And then i get this : how is this possible? :( finds 42 in {40,41,42,43} \ expected an exit code of 0, not 1
Aug 1, 2015 at 20:46 comment added jon.tre Thanks guys, on those two comments, - regarding return false, this is what i previously had, and it works fine excepts for check50 . My issue really is, my program gets the right answer, when i do this jharvard@appliance (~/Dropbox/pset3/find): ./find 42 haystack[0] = 40 haystack[1] = 41 haystack[2] = 42 haystack[3] = Found needle in haystack! -> I the get the right answer, however check50 tells me it's wrong.. sorry to bother you guys with this
Aug 1, 2015 at 20:02 comment added ChrisG Check this for the control may reach end of non-void function: cs50.stackexchange.com/questions/1647/…
Aug 1, 2015 at 19:15 comment added ebobtron The function "search", which you write must return true if needle found and false if not. Your kind of stuck with that as find has no way of knowing the result otherwise. To accomplish this you may need to simply put a return false; as the last line of the function search(). Then if the needle is not found by your conditional code search() will return false.
Aug 1, 2015 at 18:18 comment added jon.tre thanks, so i tried to to that but it either told me that non-void function 'search' should return a value or control may reach end of non-void function which kind of make sense to me since you want to know if your search was successful, right?
Aug 1, 2015 at 17:57 comment added ChrisG The specification doesn't want you to return something if the number wasn't found. Delete this line.
Aug 1, 2015 at 17:55 comment added jon.tre what kind of annoys me is not being able to see from the error message what i get wrong, since when i execute the programme, everything "seems" fine. :) , i don't see the pattern of errors in these : finds 42 in {42,43,44} :) finds 42 in {41,42,43} :( finds 42 in {40,41,42} \ expected an exit code of 0, not 1 :( finds 42 in {41,42,43,44} \ expected an exit code of 0, not 1 :( finds 42 in {40,41,42,43} \ expected an exit code of 0, not 1 :) finds 42 in {39,40,41,42} :) doesn't find 42 in {39,40,41} :) doesn't find 42 in {39,40,41,43}
Aug 1, 2015 at 17:50 comment added jon.tre yeah, I have the return 1 if the number wasn't found. Here is my code bool search(int value, int values[], int n) { int i; int m=n/2; // rejects negative numbers if (n < 0) { return false; } else { // Binary search for (i=0;i<n;i++){ // max value is less than n if (values[m] > value) {m = m/2;} else {m = m*1.5;}; // integer m autorounds if (values[m]==value){return true;}; } return false; } }
Aug 1, 2015 at 16:56 comment added ChrisG I don't think it's the same bug. Do you in any case have a command to return 1 if the number wasn't found in the array? Consider pasting your code.
Aug 1, 2015 at 16:50 history edited ChrisG CC BY-SA 3.0
code formating
Aug 1, 2015 at 16:19 review First posts
Aug 1, 2015 at 16:55
Aug 1, 2015 at 16:18 history asked jon.tre CC BY-SA 3.0