389 Posted Topics
Re: Your `power` function takes `n` and multiplies it with itself `m` times. What it should be doing is take `m` and multiply it with itself `n` times. Also `n` should be an int, not a float. | |
Re: You can't do `cout << *(POINTER + 2)` for the same reason that you can't do `cout << *POINTER` or `cout << OBJECT`: There is no overload for operator << that takes an ostream and a `CLASS`. Also `POINTER + 2` does not add two bytes to the pointer, it … | |
Re: That's because `format` returns a string. A `double` does not have a format - only a value. If you want to store formatted numbers, you need to store them in an array of strings. If you just want to store doubles, simply use 0.0 rather than `d.format(0.0)`. | |
Re: walls,corner[2] = (' #') You accidentally typed a comma instead of a period here. As a result the parser things you want to assign to a local variable called `walls` as well as to the second element of a variable named `corner`. Because of this Python now thinks that `walls` … | |
Re: > The acual value of true and false is not defined, nor is it guarenteed to be either 0 or 1 Not sure what you mean by "actual value", but converting true to an integer will give 1 and false will give 0. That's defined in section 3.9.1, paragraph 6 … | |
Re: > but I have an if after else The `if` must be *before* the `else`. | |
Re: How does it not work? Are you getting a syntax error on the funny print line? What is that line supposed to accomplish? That's not a valid use of `print`. Anyway using an empty infinite loop to prevent the turtle window from closing is a very bad idea (it will … | |
Re: No, it shouldn't. `float* t;` is a perfectly legal variable declaration in C - `float* = t;` is not. | |
Re: Use the `sum` function. | |
Re: There's already a module named `math` in Python. You'll need to name yours something else. | |
Re: > But doesn't c's memory address contain value of a+b? Yes, after it has been assigned. A better example might be `f(a+b)` where `f` takes an int reference. Since the result of `a+b` is a temporary without an address, the call is illegal, but `c=a+b; f(c);` would be fine because … | |
Re: They do, but `vowel([a], 1)` is shorter. > Count is Count in your clause in line 8 does not make sense for me Actually it's saying `Count is Count + Counter` (the lines are broken funnily), but that doesn't make sense either. Once a variable has been given a value, … | |
Re: You can't use `as` with the `from foo import bar` syntax. What would you expect that to accomplish anyway? The whole point of using `from foo` is that you don't need to use a qualified name to refer to the module's function. | |
Re: > How to change the end of std::string? You mean remove the last part of the string? Use `erase` for that. > One way that I could think of is to assign '\0' to all the trailing characters of the string but it would be inefficient to do so if … | |
Re: > If num starts at 0, then the assignment should be num = 0 then num should increment during the postfix incrementation of num!? The increment happens *before* the assignment. Postfix increment does not mean that the increment happens after the current statement. It only means that the result of … | |
Re: A variable can be referred to as either `$VARNAME` or `${VARNAME}`. The latter form is useful if the variable name is followed by something that's not supposed to be part of the variable name. For example say you have a variable `FOO` and you want to print the contents of … | |
Re: As you noticed, feeding a string that doesn't represent an integer (like "done") to `int` will cause an exception. So you should only call `int` on the user input if it is not "done". You can achieve this by putting the if above the call to `int` and put the … | |
Re: Quoting from `man stdarg`: > Multiple traversals of the list, each bracketed by va_start() and va_end() are possible. So yes, you can use a `va_list` twice. | |
Re: > The as keyword is practically the same as a cast. The difference being that if the given object doesn't have the right type, a cast will throw an exception while `as` will just return `null` instead. In this case however, there's no need to cast at all since `A` … | |
Re: `data[1:2]` is a list splice. It returns the sublist of `data` that goes from index 1 (inclusive) to index 2 (exclusive). So basically it returns a list that contains the element at index 1 and nothing else. If all you want is the element at index 1 without a list … | |
Re: Instead of defining a new variable with the same name, you could just assign a different value to the same variable, like this: public class a { protected string text = "class a"; public void alert() { MessageBox.Show(text); } } public class b : a { public b() { text … | |
Re: The only way to make `println` not call the default `toString` method is to define your own `toString` method. If you want the contents of the variables to be printed, you'll need to define a `toString` method that returns a string containing the contents of those variables. | |
Re: [Copy elision](http://en.wikipedia.org/wiki/Copy_elision) | |
Re: The program, as written, will invoke undefined behavior and most likely not depend on endianness at all. `num+1` produces a pointer that points to the address that `num` points to plus `sizeof(int)`. You then cast that pointer to `char*` and dereference it. Since `num+1` points outside of the bounds of … | |
Re: The compiler may handle function arguments either of the ways described in the article no matter what the called function looks like. | |
Re: There is no direct equivalent for `delegate` in Java, that is you can't pass methods as arguments to other methods in Java. What you do instead is to create a one-method interface and then implement it and pass an instance of it as a parameter to the given method. So … | |
Re: You set `ehealth` to 15 on line 26, which is inside the loop. Then you subtract a random amount of damage between 5 and 9. So `ehealth` is now somewehere between 6 and 10. That's still above zero, so the loop repeats, jumping back to line 23. So line 26 … | |
Re: If you're using a boolean variable as your while condition and that while loop never exits, that means that either the variable is never set to False (because the part that's supposed to set it to False is never reached for some reason) or the body of the `while` loop … | |
Re: You can't write code directly into the class body like that. It needs to be inside a method. | |
Re: while enemy.hp > 0: attack = raw_input("Which kind of attack do you want to perform against the enemy") enemy.hp -= damage_for(attack) print "The enemy is dead!" | |
Re: Let's think about what the result should look like for a non-empty list. You want a list that contains two lists, right? So the basic structure should be `(list something something-else)`. Now what do we want `something` and `something-else` to be? `something` should be a list that contains the first … | |
Re: Count is Count1 + 1 I think you meant `Count1 is Count + 1` here. PS: As your code is currently written, it counts any item in te given list - not just vowels. | |
Re: Your function returns `true` if the first elemenet of the first array is equal to the first element of the second array and `false` otherwise. That is, it always stops after the first iteration of the loop returns a result based just on that one iteration (because when a `return` … | |
Re: `[S|H]` is a pattern that says "this argument must be a list with at least one element. The first element shall be called `S` and `H` shall be a list containing all the other elements". You use `[e, t, th]` for this argument, so `S` becomes `e` and `H` becomes … | |
Re: It doesn't. The accessibility of a class's constructors and destructor only affects whether and under what conditions you can create instances of the class (specifically you can only directly create instances of the class if at least one of the constructors is accessible to you and you can only create … | |
Re: > Anyone familiar with this programming language? I am. > If so, anyone use it on the job? I do. My current project at work (at a university) is to write a translator from C to an intermediate language, which we use to perform model checking on the program (so … | |
Re: You can't use arithmetic expressions directly as arguments to predicates in Prolog - you need to asssign them to a variable using `is` and then use that as the argument: N >= 0, NM1 is N - 1, NM2 is N - 2, fib(NM1, AF), fib(NM2, BF), NF is AF … | |
Re: First note that `foo += bar` is an expression that increments `foo` by `bar` *and then evaluates to foo*. So `t += (p += sizeof(int))[-1];` can be rewritten as: p += sizeof(int); t += p[-1]; that should be a little clearer already. Next note that `foo[bar]` is simply a syntactic … | |
Re: > [you] first need to convert Array into an ArrayList<Student> No, he doesn't. Arrays can be sorted using `Arrays.sort`, which works just like `Collections.sort`, but for arrays. | |
![]() | Re: First of all you're accessing your array out of bounds when `x` is `MAXX - 1` (and thus `x + 1` is `MAXX`) or `y` is `MAXY - 1` (and thus `y + 1` is `MAXY`), so your program is invoking undefined behaviour. I think you started your loop at … |
Re: You can not change the behaviour of `<` being used with two doubles. The only thing you could do is to make `at` return a custom type instead of `E`, like a `Proxy<E>`. Then you could define `static bool operator<(E, Proxy<E>)` and that one will be called when you do … | |
Re: In C99 `sizeof` is not a compile-time operator when used on variable-length arrays. It's still a compile-time operator when used on anything else though. In C++ your code is not legal. If your compiler accepts it, that means it supports variable-length arrays for C++ as a non-standard extension. `gcc` will … | |
Re: Another thing to note is that your `if`s are all indepenedent (i.e. they're not `else if`s). So the `else` only applies to the last `if`. That means that once you've fixed the `=` vs. `==` issue, the `else` will execute whenever you entered an operator other than `*`. Anothernother thing … | |
Re: > Instead, it is acting as if the temperaturef used in the top-level code has already been set to a float value, as it is on line 52. It is on line 52, but since line 52 runs before the `display_temp` function is called on line 55, the variable has … | |
Re: There's nothing wrong with the code per se. From your output it looks like `$mean_data_sorted[$i]` is a string that ends with a line break. So the quickest way to fix your issue would be to `chomp @mean_data_sorted` before you iterate over it. Depending on how you create `mean_data_sorted`, it might … | |
Re: To make the approach used in the code posted in this thread work, you'd write a recursive function that calls `readline` and then recurses until `readline` returns `eof`. That said, it would be much easier to just use [`in-lines`](http://docs.racket-lang.org/reference/sequences.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._in-lines%29%29). | |
Re: A Python file can either be run as a program or it can be imported by another Python file as a library. `if __name__ == "__main__":` means "only run the following code, if this file was run as a program - not imported as a library". This is useful if … | |
Re: You can't compare `char*`s using the `==` operator. You need `strcmp` from the `cstring` header for that, but a better solution would be to use `std::string`s instead of `char*`s. `std::string`s can be compared using `==`. | |
Re: When do you get the segmentation fault? Right away or do you get some output before the segmentation fault? And when you input a 2-digit number, do you get wrong output for both "The inputNumber variable is :" and the result or only the latter? One problem I see is … |
The End.