简体   繁体   中英

Errors when dividing with floating point value in C

I want to take the the answer from x_rand / 0,2 and y_rand / 0,2 , and store the answer rounded down to an integer in the variable division_x and division_y :

double x_rand = drand48();
double y_rand = drand48();
int division_x = x_rand / 0,2;
int division_y = y_rand / 0,2;

These are the error messages I get:

breakout.c:95:37: error: expected identifier or '('
        int division_x = x_rand / 0,2;
                                    ^
breakout.c:95:37: error: expected ';' at end of declaration
        int division_x = x_rand / 0,2;
                                    ^
                                    ;
breakout.c:96:37: error: expected identifier or '('
        int division_y = y_rand / 0,2;
                                    ^
breakout.c:96:37: error: expected ';' at end of declaration
        int division_y = y_rand / 0,2;
                                    ^
                                    ;

breakout.c:95:33: error: division by zero is undefined
      [-Werror,-Wdivision-by-zero]
        int division_x = x_rand / 0,2;
                            ^ ~
breakout.c:96:33: error: division by zero is undefined
      [-Werror,-Wdivision-by-zero]
        int division_y = y_rand / 0,2;

Someone please explain this to me.

C does not use European style float representations. You need to use 0.2 , not 0,2 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM