User Profile

Collapse

Profile Sidebar

Collapse
scruggsy
scruggsy
Last Activity: Aug 20 '09, 12:25 AM
Joined: Mar 1 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • 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?...
    See more | Go to post

    Leave a comment:


  • 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...
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to sorting linked list in alphabetical order HELP!
    in C
    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;
    }
    ...it is possible for last to never become initialized with the address of a WordNode if execution never enters the body of your while loop, which would cause...
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to sorting linked list in alphabetical order HELP!
    in C
    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...
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to error: non-lvalue in assignment
    in C
    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.
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to error: non-lvalue in assignment
    in C
    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.
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to Forward declaration in C++ not working
    in C
    Code:
             parentClass parent;  //reference to class that created this child
    In Java I assume this would be a reference to some object. In C++ it is not. parent here is an object embedded into a child object. C++ needs to know the class layout of parent in order to determine the class layout of child.

    Forward declarations simply tell the compiler a class exists:
    Code:
    class Mystery;
    
    class Me {
      Mystery
    ...
    See more | Go to post

    Leave a comment:


  • Yes, exactly.
    In your main routine you did this:
    Code:
        int *longestMonstre, *largestMonstre, *nbrSquelettique = 0, *nbrGrassouillet = 0;
    creating 4 pointers to int initialized to zero.
    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
    ...
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to How to initialize a static class variable
    in C
    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;
    Your second example code there defines a static member function returning an object of type MyClass. I'm not sure what the compiler does...
    See more | Go to post

    Leave a comment:


  • Assuming the array is not dynamically allocated, use the sizeof operator.
    Code:
    struct Thing
    {
      int a;
      int b;
    };
    
    Thing things[5];
    Assuming a Thing occupies 8 bytes, sizeof(Thing) is 8.
    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,
    ...
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to Printing Formal Parameters
    in C
    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...
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to find even or odd in array
    in C
    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....
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to find even or odd in array
    in C
    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
    ...
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to Simple Float Question
    in C
    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);
    If you were not using literal values then you would want to do an explicit cast of one of the operands to a double.
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to Function pointers
    in C
    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....
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to Rounding in C++
    in C
    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.
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to C++: Looping Issue
    in C
    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;
    Or use a do loop instead of a while:
    Code:
    int num;
    do
    ...
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to Error E2235 in c++
    in C
    What problems? Error messages? Run-time errors?...
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to loop and declaring variable question
    in C
    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...
    See more | Go to post

    Leave a comment:


  • scruggsy
    replied to vector push_back
    in C
    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)....
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...