The Big Programming Thread - Page 85
| Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
|
mmp
United States2130 Posts
| ||
|
Quasimomo
Netherlands4 Posts
On October 12 2011 07:47 Ripense wrote: As far as I can see you call the method getSensorValue on the interf variable which is no initialized and therefore throws a NullpointerException. You need to do something like inter = new InterfaceKitPhidget(); before calling methods on it. I'm glad you see what's wrong with it :D but... could you perhaps explain in more detail please? I've only been working with java for a couple of weeks so I don't really know where look for things and where to put them =( | ||
|
Keitzer
United States2509 Posts
:void in Objective-C++? Been bugging me all day since I can't find out how | ||
|
Ripense
Austria23 Posts
On October 12 2011 08:08 Quasimomo wrote: I'm glad you see what's wrong with it :D but... could you perhaps explain in more detail please? I've only been working with java for a couple of weeks so I don't really know where look for things and where to put them =(
In this part you declare some variables. The declaration alone does not assign an object to the variable. For the variable vlc you assign an object (new VLCv2("localhost", 1234). However the other variables are still null. At some point in you code you need to have the other variables on the left side of an assign operation before you use them otherwise, or the will still be null. That's what I think is the problem, because at
you call the function getSensorValue(int) on the interf variable, but this variable is still null (not defined) as there isn't a point in the code, where interf is assigned an object. Similar to your vlc variable you need to assign an object to the interf variable before calling the method. Depending on your code this could be as easy as assigning the object during declaration as you did with the vlc variable
See the following code snippet for a simplified version of the problem in your code. Analog to your readSensorValue method in this case the testproc method throws a NullPointerException, because the String variable a is not defined.
I hope this clarifies my earlier statement. To avoid such problems, always make sure, that a value or object is assigned to your variables before using them. | ||
|
KaiserJohan
Sweden1808 Posts
I am talking about making a website that takes between 1-2 hours from scratch at most. Drag-and-drop stuff which then produces a .html document would be sweet. | ||
|
Butterednuts
United States859 Posts
On October 13 2011 01:45 KaiserJohan wrote: I need to make a really quick and simple website. What is the best tool available? I am talking about making a website that takes between 1-2 hours from scratch at most. Drag-and-drop stuff which then produces a .html document would be sweet. Wordpress offers pretty good starting points, where you can change it almost entirely from a blog to anything you want. | ||
|
Necosarius
Sweden4042 Posts
| ||
|
KaiserJohan
Sweden1808 Posts
On October 13 2011 01:55 Butterednuts wrote: Wordpress offers pretty good starting points, where you can change it almost entirely from a blog to anything you want. Is there any other tools that you can work with offline? | ||
|
Frigo
Hungary1023 Posts
On October 13 2011 01:58 Necosarius wrote: I have a hard time understanding recursion. Could someone please explain what it is/what it does? A recursive function might call itself with different parameters to compute its return value, that's all. For example, factorial calculation: public class Main Another common example, calculating the Fibonacci number: public class Main | ||
|
Millitron
United States2611 Posts
On October 13 2011 01:58 Necosarius wrote: I have a hard time understanding recursion. Could someone please explain what it is/what it does? Recursion is a general idea for creating methods. A recursive method has a simple answer for some base case, and calls itself for any other cases. The recursive calls generally try to whittle the problem down to a base case, then merge the returns of each call. The Fibonacci and the factorial example, while being relatively easy to understand, are computationally very slow. There are much faster algorithms that don't use recursion. | ||
|
killa_robot
Canada1884 Posts
On October 13 2011 01:58 Necosarius wrote: I have a hard time understanding recursion. Could someone please explain what it is/what it does? Recursion just means a method calls itself until it reaches some sort predetermined value. In this case, the method calls itself until it reaches zero. Since it calls itself there's only ever one of it, so it's static.
| ||
|
Kambing
United States1176 Posts
On October 13 2011 01:58 Necosarius wrote: I have a hard time understanding recursion. Could someone please explain what it is/what it does? First thing to recognize: programming is problem solving by decomposition. Given a problem, you decompose that problem repeatedly into smaller problems until the subproblems are manageable to solve on their own. For example, the problem of cooking spaghetti involves several subtasks such as buying the ingredients, preparing the sauce, preparing the meat, and the mixing it all together. In code, you typically use functions/methods to realize this decomposition, e.g.,
With that in mind, recursion is a problem solving technique in which you recognize that the subproblems that you create are actually smaller versions of the original problem that you are trying to solve. To make this more concrete, imagine a line of folk waiting for the release of heart of swarm:
Now imagine that the person in the back of line is trying to figure out what place they are in line. One thing they can do is step out of line and count the number of people in front of them directly. However, instead of risking losing their place in line, they can ask the person in front of them:
Now, the person in front of them is posed with a similar question, so they can ask the person in front of them the same question:
Finally the question is posed to the person in the front of the line. He's know he's #1, so he tells the person behind him.
With that answer, the person behind the first in line now knows what place they are in line. They know they're second by adding one to the place of the person in front of them.
And finally the person in the back knows their place in line given the position of the person in front of them by adding one.
This is the essence of simple recursion:
Let's extend this to a code example that people have mentioned already, factorial(n).
| ||
|
Frosticles
United States50 Posts
The compile has no problem with it, but for some reason it is not outputting anything. Please point out my mistake. + Show Spoiler + #include <iostream> using namespace std; const int MAXELS = 9; void show(int [MAXELS]); int main () { double temps[MAXELS] = {6.5, 7.2, 7.5, 8.3, 8.6, 9.4, 9.6, 9.8, 10.0}; return 0; } void show(int temps[MAXELS]) { int i; for (i = 0; i < MAXELS; i = (i + 1)) cout << temps[i] << endl; return; } NEVERMIND FOUND MY ERROR!!! :DD | ||
|
Frigo
Hungary1023 Posts
| ||
|
Blisse
Canada3710 Posts
All the numbers to be entered will have two decimal places, and the total of the numbers entered won't be greater than 1 000 000.00 . I have to split this total into equal parts and print out the integer total and the cents since this is formatting for money. My problem is that the precision of the numbers is really terrible so entering 999 999.99 three times and dividing it equally gives me 999 999.98 for some reason. I'm using double which is supposed to be more precise than float... so I'm confused when stuff like this comes out. Any suggestions on how to preserve precision when working with large decimal numbers? I'm also outputting with printf and %f. It's not very clear to me what's the best way to output decimal numbers or store them. | ||
|
EvanED
United States111 Posts
(I'm not really kidding either. That really is something that basically no one should ever do.) | ||
|
Blisse
Canada3710 Posts
On October 13 2011 15:25 EvanED wrote: Very simply. Never use floating point numbers (doubles count) for money. :-) (I'm not really kidding either. That really is something that basically no one should ever do.) What should I use for money then? The input has two decimal places... ? I don't remember getting these kinds of errors in Python, but I'm using C now, and the lesson is supposed to be learning how to deal with the doubles I think... | ||
|
Deleted User 101379
4849 Posts
On October 13 2011 17:16 Blisse wrote: What should I use for money then? The input has two decimal places... ? I don't remember getting these kinds of errors in Python, but I'm using C now, and the lesson is supposed to be learning how to deal with the doubles I think... Floating point numbers have problems with precision. On the first look they work, but then you end up having customers pay only 0.99 cent instead of 1 euro. For money you have to use a fixed point type (or in C you usually calculate with cents instead of euros/dollars) as they have exact instead of approximate representations. | ||
|
Sky
Jordan812 Posts
A quote from another forum: #include <stdio.h> each of us has a return value, but only very few of us are able to know what the return value we pass back is when our run-time ends and we hand ourselves over to the system. -TheFloorIsNowBacon | ||
|
Craton
United States17264 Posts
| ||
| ||
:void in Objective-C++? Been bugging me all day since I can't find out how