[英]Errors when dividing with floating point value in C
我想借此從答案x_rand / 0,2
和y_rand / 0,2
,並存儲答案向下舍入變量整數division_x
和division_y
:
double x_rand = drand48();
double y_rand = drand48();
int division_x = x_rand / 0,2;
int division_y = y_rand / 0,2;
這些是我收到的錯誤消息:
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;
有人請向我解釋一下。
C不使用歐式浮點表示形式。 您需要使用0.2
而不是0,2
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.