389 Posted Topics
Re: You're asking the player for his choice (by calling `humanChoice`) twice: Once in `main` and once in `printScore`. PS: On line 24 you will always break because the condition `choice == 'Q' || 'q'` is always true (because 'q' is true). | |
![]() | Re: Your else branch is missing a closing }. As a tip for the future: Many browsers have some sort of Javascript console, which lists any errors that were encountered while trying to execute the Javascript on the current page. Looking at the messages in that console will help you find … |
Re: I think you want `if( getVal.indexOf("pepsi") != -1)`. Note that this also returns true if the given string looks like "FOO,BARpepsiBLA,BAZ". If you want to avoid that you can either split the string or use arrays instead of strings in the first place. PS: There's no need for loop labels … | |
Re: There is no string literal (T_STRING) on line 11 in the file you posted. Are you sure the file you posted is the one the error messsage is complaining about? | |
Re: I think you might get more help if you described your recursive algorithm instead of requiring us to discern it from your uncommented code. Anyway I think the standard dynamic programming solution for the coin change problem can be adjusted to work for this variation of the problem. | |
Re: When you create the array it does only have 3 elements in it. That doesn't mean you can't add more to it. | |
Re: > Is there any way to make A work without using new (that includes placement new)? No, non-POD classes can not be allocated dynamically without using `new`. As far as the standard is concerned, it's undefined behavior to not use `new`. In practice the problem is, as you suspected, the … | |
Re: One mistake I immediately saw (though it's probably not the only one and might not be what's causing your crash) is that you're returning `x[i][j]` on line 91, but `i` and `j` are equal to Max and MAX (horrible names by the way) after the loop, so that's an out … | |
Re: Have you tried to run your code in the debugger to find out which line the segmentation fault happens on? Have you tried to run your code through valgrind to find out when and where you write to or read from invalid memory? Also can you give us some sample … | |
Re: The error on line 21 is that you forgot the () to call the function. So you're trying to assign a function to a double variable. The error on line 105 is that the argument to scanf needs to be a pointer, not a double. Also you're using openfilewrite uninitialized, … | |
Re: If your method calls a method that can throw an IOException (like `ImageIO.read` does), you either need to catch the exception or declare that your method may throw an IOException too (which you do by adding `throws IOException` to your method's signature). You have to do this because IOException is … | |
Re: > Do we need to pay fee to Oracle if we sell our game on the market or host it on our own web site with advertisement on the game page? No. > Also can we sell software written in Java? Yes. | |
Re: When you call a method, you don't spell out the type of the arguments - you only do that when declaring the method. I.e. if you want to call `drawHexagon` with `width` as its argument, you write `drawHexagon(width)` not `drawHexagon(int width)`. That said, unless the SimpleTurtle class has a static … | |
Re: > Can the two features of C++ Function overloading and function templates be applied together ?? Yes. You can define multiple functions with the same name even if one or all of the overloads are template functions. When you do this, the non-templated overloads will be considered first and if … | |
Re: There's nothing in your code that would reset the value of plus. However with your constructors the way they are, there is no way to create a tuna object that has the numbers as well `plus` set to a meaningful value. So I'm guessing when you use your code, you're … | |
Re: There is nothing you can do to make `newtype f = 1` work. Java doesn't allow implicit conversions for non-primitive types. There's also no way to make arithmetic operators like + etc. work with your newtype class. Using a user-defined number class will always look different than using primitive numbers … | |
Re: Your code is wrong. It has a couple of syntax errors and you're accessing your array out of bounds. The last valid index for an array of size n is n-1, so your for-loops should use <, not <=. Also the inner for-loop doesn't ensure that $j is a valid … | |
Re: There are many GUI libraries for Linux/X11. The most popular ones are GTK (the one that Gnome and XFCE use (among others)) and Qt (the one that KDE uses). Both of them run on all major platforms, not just X11. | |
Re: Your types are wrong. Your compiler should have warned you about that. If it didn't, increase your warnings level - that will save you a lot of pain in the future. arrayptr and rowptr should have types `char*` and `char**` respectively. Since you made arrayptr and int-pointer, your second for … | |
Re: I can't reproduce the behavior you're describing. Your code doesn't produce the output you say it does - your code doesn't even compile. If I correct the code's syntax error, the result will always be the empty list because you have overlapping cases with the less specific case coming first. … | |
Re: a) In Java we usually speak of "object references", not "memory addresses". Memory addresses are a low-level concept that isn't really visible to Java programmers. But yes, when you pass m2 to the Mixer constructor, you're passing a reference to the object that m2 refers to. So the m1 variable … | |
Re: `secondString = number_list[1:2]` will give you a list that contains the second string as its only element. Then when you do `secondString[0:2]` you're saying "take the first two elements of this list", but the list only has one element, so you get the same list back unchanged. What you want … | |
Re: One obvious problem I can see is that you call `malloc(sizeof(treepointer))` to allocate memory for a node of the tree, but that will only allocate enough memory to store a pointer. You need to allocate enough memory to store an entire node, so you need to use `sizeof(nodo)` as the … | |
Re: You need it because you don't know whether x_1 is greater or less than x_0. If x_1 is less than x_0, then `x_1 - x_0` will be negative and thus less than pres even if x_1 and x_0 are far apart. | |
Re: Your copy constructor calls your setFoo methods. Your setFoo methods use delete on the old value of the variable that they're setting. When the copy constructor is invoked, the variables won't have old values because the object is brand new. That means that your setFoo methods will call delete on … | |
Re: You're getting the parse error because you forgot a semicolon on line 2. Whenever you get "Unexpected blabla" at the beginning of a line, there's a good chance that you forgot a semicolon on the line before. | |
![]() | Re: You have a plus sign on either side of choice. But on the left side there's no left operand for addition. So the left plus is interpreted as the unary plus operator (which is the opposite of the unary minus (negation) and basically does nothing on numeric operands). Like most … |
Re: > when break() occurs, i assumed that it would be a clean break() It is. > but clearly it isnt turning out so, and acc[i] is catching a junk value. When break occurs it leaves the loop just as it should. But acc[i] simply isn't initialized. Let's play it through … | |
Re: You can use the `str_replace` function to replace each occurence of "." in `$description` with `".\n"`, i.e. to insert a newline (\n) after each period. If you want to display your string as HTML, you should use "<br>" instead of (or in addition to) "\n". | |
Re: QRC files are XML files, so comments can be written using the XML comment syntax: <!-- This is a comment! --> | |
![]() | Re: Your Javascript shows a bit of a Python influence. In Javascript you use curly braces to denote the beginning and end of a function body - not indentation. And there's no colon after the function signature. |
Re: You're missing a semicolon at the end of line 40, so the parser is confused when it sees the variable at the beginning of line 41. | |
Re: The problem is unrelated to the fact that test takes a variable number of arguments. The problem is that you're calling `test` as if it was a method of the `VariableArguments1Test` class, which it's not. If you want to call a static method of another class, you'll need to specify … | |
Re: csc.exe is the C# compiler that comes with Microsoft's .net SDK. mcs is the C# compiler that comes with Mono. Neither of these ship with MonoDevelop, but you need to have one of them installed in order to use MonoDevelop. So if you want to find csc.exe, you should look … | |
Re: Image.FromStream throws an ArgumentException if you call it with null as an argument or if the given stream does not contain an image in a valid (and supported) format. Since you set streamImage on the line above, it is probably safe to assume that it is not null. So the … | |
Re: Also you create a new Random object each time you call RandomNumber. This won't cause a compilation error or anything, but it will cause RandomNumber to return the same number repeatedly when invoked multiple times in a short period of time (e.g. in a loop). You should create a new … | |
Re: > How to implement sizeof api. Means sizeof is already there but i do not want to use that. You can get the size of a given type T by doing by adding 1 to a T null pointer and then converting the result to a size_t. You can get … | |
Re: Your code doesn't seem to match your description at all. You said the function should return a Rectangle, but the function in the code actually takes a rectangle (that it never uses) and returns an int. Your function also calculates the area of the rectangle that the user entered which … |
The End.