0

The following error occurs in the lines where the velocity of the ball is initialized/changed using the drand48 function:

When velocity is initialized :

if(getEventType(event) == MOUSE_CLICKED)
{
    velocity_x = 3.0 * drand48;
    velocity_y = 3.0 * drand48;

    flag = false;
}

When velocity is changed after colliding :

if (strcmp(getType(object), "GRect") == 0 && object != paddle)
{
    velocity_y = (-velocity_y/velocity_y) * 3 * drand48; //erroneous statement
    removeGWindow(window, object);
}

else if (object == paddle)
{
    velocity_y = (-velocity_y/velocity_y) * 3 * drand48; //erroneous statement
}

Console :

jharvard@appliance (~/Dropbox/pset4): make breakout 
clang -ggdb3 -Ispl/include -O0 -std=c99 -Wall -Werror -Wno-unused-variable -o breakout breakout.c -Lspl/lib -lcs -lm
breakout.c:94:30: error: invalid operands to binary expression ('double' and
      'double (*)(void)')
            velocity_x = 3.0 * drand48;
                         ~~~ ^ ~~~~~~~
breakout.c:95:30: error: invalid operands to binary expression ('double' and
      'double (*)(void)')
            velocity_y = 3.0 * drand48;
                         ~~~ ^ ~~~~~~~
breakout.c:140:59: error: invalid operands to binary expression ('double' and
      'double (*)(void)')
                velocity_y = (-velocity_y/velocity_y) * 3 * drand48;
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~
breakout.c:146:59: error: invalid operands to binary expression ('double' and
      'double (*)(void)')
                velocity_y = (-velocity_y/velocity_y) * 3 * drand48;
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~
4 errors generated.
2

drand48 is a function that takes no arguments and returns a double. It's declared in stdlib.h. You should call it like

drand48();
3
  • How to make the random number to be between 1 and 20?
    – julio
    Aug 28 '14 at 0:37
  • @julio you may take a look at this: cs50.stackexchange.com/a/1687/1161
    – kzidane
    Aug 28 '14 at 9:04
  • Thanks.. I did check that.. but you are missing the (int) before the drand48(), thats why my code was not working..
    – julio
    Aug 30 '14 at 1:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .