what's wrong?

Q

questions

# include <stdio.h>
# include <math.h>
int main()
{ long int x,y;

printf("enter an integer\n");
scanf("%d",&x);

y=x%pow(10,3);

printf("the result is %d",y);

return 0;}

The compiler tell me there is something wrong with the "pow",but I
don't know what's the wrong?
 
K

Kai-Uwe Bux

questions said:
# include <stdio.h>
# include <math.h>
int main()
{ long int x,y;

printf("enter an integer\n");
scanf("%d",&x);

y=x%pow(10,3); [snip]
The compiler tell me there is something wrong with the "pow",but I
don't know what's the wrong?

pow() returns a floating point (in this case, I guess a double) and x is a
long int. That is not a valid pair of operand types for the % operator.


Best

Kai-Uwe Bux
 
Z

Zeppe

questions said:
# include <stdio.h>
# include <math.h>
int main()
{ long int x,y;

printf("enter an integer\n");
scanf("%d",&x);

y=x%pow(10,3);

printf("the result is %d",y);

return 0;}

The compiler tell me there is something wrong with the "pow",but I
don't know what's the wrong?

my compiler says:

testmod.cpp:8: warning: format ‘%d’ expects type ‘int*’, but argument 2
has type ‘long int*’
testmod.cpp:10: error: invalid operands of types ‘long int’ and ‘double’
to binary ‘operator%’
testmod.cpp:12: warning: format ‘%d’ expects type ‘int’, but argument 2
has type ‘long int’

It looks pretty much clear. Listen to your compiler. It's your friend.

Best wishes,

Zeppe
 
S

Sjouke Burry

Kai-Uwe Bux said:
Nit: 1000 does not occur in the above whereas 1000.0 does occur.


Best

Kai-Uwe Bux
Another nit : Seeing the % sign suggests that the intent is to use 1000
 
K

Kai-Uwe Bux

Juha said:
But 1000 would work, whereas 1000.0 wouldn't.

Ah, now I understand your point: you meant to replace pow(10,3) by 1000.


Sorry for the noise.

Kai-Uwe Bux
 
Q

questions

questions said:
# include <stdio.h>
# include <math.h>
int main()
{ long int x,y;
printf("enter an integer\n");
scanf("%d",&x);
y=x%pow(10,3);
[snip]
The compiler tell me there is something wrong with the "pow",but I
don't know what's the wrong?

pow() returns a floating point (in this case, I guess a double) and x is a
long int. That is not a valid pair of operand types for the % operator.

Best

Kai-Uwe Bux

thanks
 
Q

questions

my compiler says:

testmod.cpp:8: warning: format '%d' expects type 'int*', but argument 2
has type 'long int*'
testmod.cpp:10: error: invalid operands of types 'long int' and 'double'
to binary 'operator%'
testmod.cpp:12: warning: format '%d' expects type 'int', but argument 2
has type 'long int'

It looks pretty much clear. Listen to your compiler. It's your friend.

Best wishes,

Zeppe- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,917
Members
47,458
Latest member
Chris#

Latest Threads

Top