389 Posted Topics

Member Avatar for 2384443

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.

Member Avatar for 2384443
0
132
Member Avatar for nmakes

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 …

Member Avatar for deceptikon
0
154
Member Avatar for Nandomo

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)`.

Member Avatar for jwenting
0
236
Member Avatar for Liam_1

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` …

Member Avatar for TrustyTony
0
707
Member Avatar for new_developer

> 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 …

Member Avatar for Ancient Dragon
0
220
Member Avatar for vyalineconstantino
Member Avatar for james.lu.75491856

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 …

Member Avatar for james.lu.75491856
0
2K
Member Avatar for Vinod Supnekar
Member Avatar for ram619

No, it shouldn't. `float* t;` is a perfectly legal variable declaration in C - `float* = t;` is not.

Member Avatar for ram619
0
195
Member Avatar for entropic3105
Member Avatar for entropic3105

There's already a module named `math` in Python. You'll need to name yours something else.

Member Avatar for entropic3105
0
338
Member Avatar for nchy13

> 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 …

Member Avatar for nchy13
0
840
Member Avatar for Dili1234

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, …

Member Avatar for TrustyTony
0
2K
Member Avatar for james.lu.75491856

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.

Member Avatar for sepp2k
0
56
Member Avatar for nchy13

> 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 …

Member Avatar for NathanOliver
0
960
Member Avatar for TokamakFusion

> 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 …

Member Avatar for bibiki
-2
465
Member Avatar for asrsmunna

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 …

Member Avatar for sepp2k
0
332
Member Avatar for stealthless

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 …

Member Avatar for edward.okech.5
0
228
Member Avatar for Learningvinit

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.

Member Avatar for nitin1
0
2K
Member Avatar for Karan_4

> 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` …

Member Avatar for ddanbe
0
101
Member Avatar for toniann.midori

`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 …

Member Avatar for toniann.midori
0
3K
Member Avatar for valipour

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 …

Member Avatar for sepp2k
0
243
Member Avatar for murali2489

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.

Member Avatar for murali2489
0
198
Member Avatar for mahesh113
Member Avatar for nitin1

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 …

Member Avatar for nitin1
0
147
Member Avatar for Garrett2011

The compiler may handle function arguments either of the ways described in the article no matter what the called function looks like.

Member Avatar for sepp2k
0
324
Member Avatar for abra_ka_dabra

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 …

Member Avatar for sepp2k
0
629
Member Avatar for Jacklittle01

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 …

Member Avatar for Jacklittle01
0
150
Member Avatar for Jacklittle01

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 …

Member Avatar for sepp2k
0
119
Member Avatar for tanmay.majumdar2

You can't write code directly into the class body like that. It needs to be inside a method.

Member Avatar for pbj.codez
0
170
Member Avatar for Jacklittle01

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!"

Member Avatar for sepp2k
0
84
Member Avatar for Scythe1213

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 …

Member Avatar for sepp2k
0
482
Member Avatar for Dili1234

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.

Member Avatar for Dili1234
0
2K
Member Avatar for eldiablo1121

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` …

Member Avatar for Moschops
0
198
Member Avatar for Dili1234

`[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 …

Member Avatar for Dili1234
0
174
Member Avatar for vishalonne

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 …

Member Avatar for David W
0
259
Member Avatar for Ancient Dragon
Re: F#

> 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 …

Member Avatar for sepp2k
0
120
Member Avatar for Dili1234

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 …

Member Avatar for Dili1234
0
220
Member Avatar for nitin1

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 …

Member Avatar for Banfa
0
311
Member Avatar for sk8ergirl

> [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.

Member Avatar for JamesCherrill
0
172
Member Avatar for Jenniferting

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 …

Member Avatar for sepp2k
0
253
Member Avatar for sparkthesunoff

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 …

Member Avatar for sepp2k
0
296
Member Avatar for nitin1

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 …

Member Avatar for sepp2k
0
188
Member Avatar for SpottyBlue

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 …

Member Avatar for sepp2k
0
264
Member Avatar for jtjudge

> 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 …

Member Avatar for jtjudge
0
216
Member Avatar for rajesrmbioinfo

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 …

Member Avatar for 2teez
0
171
Member Avatar for captainhair

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).

Member Avatar for sepp2k
0
300
Member Avatar for nouth

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 …

Member Avatar for nouth
0
508
Member Avatar for ngkevi1994

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 `==`.

Member Avatar for Lucaci Andrew
0
392
Member Avatar for lewashby

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 …

Member Avatar for tinstaafl
0
122

The End.