2014-02-15 18 views
-1
#include <stdio.h> 
int main(){ 
    float a; 
    printf("Enter Real Number: "); 
    scanf("%f", &a); 
    int b; 
    b=a*0.393701/12; 
    float c; 
    c=a*0.393701%12; 
    printf("b, c"); 
    return 0; 
} 

給出了錯誤數學相關的C++

10|error: invalid operands of types 'float' and 'double(double, double)' to binary 'operator*'| 
10|error: expected ';' before 'of'| 

有人能指出錯誤嗎?

回答

3

只能在整數類型(charshortintlong等)使用模運算符%

此外,您可能想要將printf("b, c")更改爲printf("%d, %f",b,c)

+0

太棒了,它做了詭計,非常感謝:)) – Dish

+0

別忘了['fmod(...)'](http://www.cplusplus.com/reference/cmath/fmod/)。在C++中可能沒有操作符這樣做(操作符***是爲Java中的浮點類型定義的),但它自從C以來一直是標準庫的一部分。 –

0

如果你想找出兩個浮點數的模然後用fmod(real_number,real_number);

例如模運算符不能在浮動

0

操作: -

fmod(5.5,1.3); 

輸出:0.300000