I'm not clear on what you need, then.
Do you already have an algorithm to compute the numbers, or are the numbers precomputed? That would be the first step before you can worry about printing them.
If you've already got the first step down, are you stuck on how to output the numbers to the screen?...
User Profile
Collapse
-
Some thoughts:
-for every number c less than n, c + (n - c) = n
-given the above, you can do this recursively. For instance, if 2 + 3 = 5 then the numbers summing to 2 plus the numbers summing to 3 also = 5.
-you only have to calculate sums for numbers from (n/2) through n; below that the sums are the same, just reversed. i.e.
4 + 2 = 6
3 + 3 = 6
2 + 4 = 6 <- you can stop at 3 + 3
Hope...Leave a comment:
-
Okay. You are getting a run-time error then, not a compile-time error as you indicated in your first post.
In this bit:
Code:WordNode *last; while(current!=NULL && current->word<word) { last=current; current=current->link; }
Leave a comment:
-
I don't see a syntax error on that line. To be honest, assuming list and word are defined, the code ought to compile. Can you post the text of the error message you are receiving and confirm the line referenced by the error message?
Your code seems rather complicated for such a simple task. I think you can reduce it to a single, short loop.
I am assuming you intend to add code to delete the WordNodes you've allocated...Leave a comment:
-
Read newb16's post again.
DATA_CW is a macro, not a variable. It is replaced by the compiler with '63' wherever it occurs in your code. You cannot assign to it. Use a variable.Leave a comment:
-
Your error says line 463. Which of those lines is 463?
You have an assignment involving something called DATA_CW, but you didn't post the code which defines DATA_CW.
More info == more help.Leave a comment:
-
Code:parentClass parent; //reference to class that created this child
Forward declarations simply tell the compiler a class exists:
Code:class Mystery; class Me { Mystery
Leave a comment:
-
Yes, exactly.
In your main routine you did this:
Code:int *longestMonstre, *largestMonstre, *nbrSquelettique = 0, *nbrGrassouillet = 0;
You never assign a valid address to nbrSquelettique or nbrGrssouillet in your code, so *nbrSquelettiqu e is an error - the pointer doesn't point to anything.
In MonstreFill() you do this:
Code:nbrSquelettique = i; nbrGrassouillet
Leave a comment:
-
static members need to be initialized outside of the class definition (the only exception is for constant integers).
Code:// Thingy.h class Thingy { static float someNum; ... }; // Thingy.cpp float Thingy::someNum = 5.432;
Leave a comment:
-
Assuming the array is not dynamically allocated, use the sizeof operator.
Code:struct Thing { int a; int b; }; Thing things[5];
sizeof(things) is the size of each element times the number of elements: 5 * 8.
You can't pass the array to a function and use sizeof on it. You can however use a macro.
Code:#define ARR_SIZE(ARR,
Leave a comment:
-
Yes: give them names.
void add(int, int) tells the compiler what number and types of arguments the function expects. It doesn't care whether you give them names or not; either way the arguments are passed according to the calling convention each time you call the function. By default the compiler generates code that pushes b onto the stack followed by a. The only difference between void add(int, int) and void add(int x, int y) is that your...Leave a comment:
-
Not to be nitpicky (or rather, to be very nitpicky :p) but zero is a multiple of all numbers but a factor of none. Negative even numbers are also multiples of 2. Whether either applies in this case depends on the problem statement I guess - OP doesn't specify....Leave a comment:
-
Any even number is a multiple of 2. No odd number is. So it looks like you already have most of the code to do this, you just need to do it inside a loop inspecting the elements of your array one at a time. If that's the part you're having trouble with, post what you've tried.
As a somewhat useless aside, another way to test if an integer is odd or even:
Code:if (a & 1) // odd else // even
Leave a comment:
-
As mentioned previously if one of the operands is a double then the other will be promoted to double as well.
Since you are using the literal (integer) value '2' just replace it with '2.0' to get the desired result.
Code:median= ((value[length/2]+value[length/2+1]) / 2.0);
Leave a comment:
-
You see nothing about function pointers there because foreach is a template function. You can instantiate it with any type for f so long as calling f(*first++) is a legal operation. This means f must be a function taking one argument or an object of a class with an overloaded operator()() method taking one argument. Moreover because first is of type In, f must take an argument convertible to whatever type In is when the template is instantiated....Leave a comment:
-
One way to do it: add 0.005, multiply by 100, and cast to an integer, then divide by 100 and store the result in a float.Leave a comment:
-
That error message means exactly what it says.
Some languages will automatically initialize variables. C++ won't. So declaring a variable and then using it without first somehow assigning it a value is an error - because it's uninitialized, there's no way of knowing what value it contains.
You should either initialize num to some value:
Code:int num = 0;
Code:int num; do
Leave a comment:
-
-
MSVC++ does scopes; a local identifier with the same name as a global hides the global.
OP, your code is a bit of a mess. As boxfish said your while loop belongs inside main() - or at least inside some function. The compiler should be complaining about that.
That issue aside, if you indent your code you'll see that your four double variables are not declared globally; they are declared as local to the scope of your while...Leave a comment:
-
I am assuming that item.push_back( item) is supposed to be list.push_back( item), right?
In that case, notice that item is of type object, whereas the vector holds pointers to objects. You may have intended to do list.push_back( &item)....Leave a comment:
No activity results to display
Show More
Leave a comment: