2016-04-26 91 views
-1

我发现了其他运营商的答案,但好像%都有自己的属性:如何解决错误...类型'int'和'float'的无效操作数到二进制'操作符%'?

#include <iostream> 
#include <cmath> 

using namespace std; 

int main() 

{ 
float pprice; 
cout << "Enter the purchase price =>" << endl; 
cin >> pprice; 
float cash = 10000%pprice; 
return 0; 
} 

//错误:类型“诠释”和“浮动”二进制“操作符%”

的无效操作数这只是显示相同错误的代码示例。请问我该如何解决这个错误?

+0

关闭作为重复,这解释了错误,但我不知道你是否意味着'pprice%10000' –

回答

2

%运营商只适用于类型int(See here)。对于浮动,您需要使用fmod

相关问题