简体   繁体   English

用C中的浮点值除法时出错

[英]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 : 我想借此从答案x_rand / 0,2y_rand / 0,2 ,并存储答案向下舍入变量整数division_xdivision_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. C不使用欧式浮点表示形式。 You need to use 0.2 , not 0,2 . 您需要使用0.2而不是0,2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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