Solution:
You've abject victim to the most vexing parse, which refers this isanumber
is being employed as a function. Take out the parentheses and you must be fine:
int thisisanumber;
Further consider making it a bit more readable, like thisIsANumber
. In case you ever require to know it, thisIsANumber
uses the camel-case naming convention.
Declare your variable without brackets, see the below statements
int thisisanumber;
Now, you know with brackets, it is interpreted as a function, and a function can't be passed as a parameter to the >>
operator.
Your issue is the reputed most vexing parse. Originally everything, which could be parsed as a function declaration will be parsed as such. Hence the compiler will interpret int thisisanumber();
as a declaration of a function thisisanumber
taking zero arguments and returning an int
. In case you consider this behaviour the issues with cin>>thisisanumber;
must be somewhat selfevident.
In case you remove the parantheses, altering the variable declaration to int thisisanumber;
, your program must behave like you'd expect it to with thisisanumber
being a variable of type int
.
You might but reconsider your naming usage, thisisanumber
isn't accurately readable. I would point out going with this_is_a_number
, thisIsANumber
or ThisIsANumber
.
The surplus operator (otherwise known as the modulo operator) %
is a binary operator (for example takes accurately 2 operands) and operates just on integer types (for example short
, int
, long
, long long
, etc).
It looks from the error message that the variable number1
is of type double
. Further, the function pow
from the math library returns a value of type double
. These two values are the main reason for the error.
There are numerous solutions to this each of which rely on what you want to do. I'll unravel a couple of them:
- throwing the operands to
int
s
foo = (int) bar % (int) quux; // WARNING: you'll be risking to lose data
- Declaring
number1
to be of an int
type and writing your own version of pow
that perhaps takes and returns int
s
// works only for non-negative integer exponents
int myPow(int n, int exp)
{
int result = 1;
for (; exp > 0; exp--)
result *= n;
return result;
}
// some code
foo = number1 % pow(bar, quux);
Declaring number1
to be of an int
type and employing a library function like round
, to round the value returned from pow
then throwing it to an int
foo = number1 % (int) round(pow(bar, quux));