Po kompilacji programu otrzymuję poniżej błędunieprawidłowe argumenty typów int i double na binarny „operator%”
invalid operands of types int and double to binary 'operator%' at line
"newnum1 = two % (double)10.0;"
Dlaczego tak jest?
#include<iostream>
#include<math>
using namespace std;
int main()
{
int num;
double two = 1;
double newnum, newnum1;
newnum = newnum1 = 0;
for(num = 1; num <= 50; num++)
{
two = two * 2;
}
newnum1 = two % (double)10.0;
newnum = newnum + newnum1;
cout << two << "\n";
return 0;
}
'(double) 10.0' ten typecast nic nie robi. 10.0 jest już podwójnym rodzajem. 10.0f to typ zmiennoprzecinkowy, a 10 to (podpisany) typ całkowity. – Lundin
@Lundin: '10' jest specyficzne dla typu' int', a nie tylko dowolnego dowolnego typu liczbowego ze znakiem. –