-1

I found answers for other operators but it seems like % has its own properties:

#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;
}

//Error: invalid operands of types 'int' and 'float' to binary 'operator%'

This is only a sample of the code which displays the same error. Please how can I fix this error?

danday74
  • 52,471
  • 49
  • 232
  • 283
Abdul
  • 11
  • 1
  • 2
  • 3
  • Closing as duplicate which explains the error, although I wonder if you meant `pprice % 10000` instead – M.M Apr 26 '16 at 07:52

1 Answers1

2

The % operator only works on type int (See here). For float you need to use fmod.

Community
  • 1
  • 1
Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175