Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what's wrong?

1 view
Skip to first unread message

questions

unread,
Oct 28, 2008, 7:21:36 AM10/28/08
to
# 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?

Kai-Uwe Bux

unread,
Oct 28, 2008, 7:49:19 AM10/28/08
to
questions wrote:

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

Zeppe

unread,
Oct 28, 2008, 7:56:07 AM10/28/08
to

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

Juha Nieminen

unread,
Oct 28, 2008, 1:53:37 PM10/28/08
to
questions wrote:
> y=x%pow(10,3);

What's wrong with 1000?

Kai-Uwe Bux

unread,
Oct 28, 2008, 2:22:21 PM10/28/08
to
Juha Nieminen wrote:

Nit: 1000 does not occur in the above whereas 1000.0 does occur.


Best

Kai-Uwe Bux

Sjouke Burry

unread,
Oct 28, 2008, 3:38:00 PM10/28/08
to
Another nit : Seeing the % sign suggests that the intent is to use 1000

Juha Nieminen

unread,
Oct 28, 2008, 6:55:34 PM10/28/08
to

But 1000 would work, whereas 1000.0 wouldn't.

Kai-Uwe Bux

unread,
Oct 28, 2008, 7:18:20 PM10/28/08
to
Juha Nieminen wrote:

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


Sorry for the noise.

Kai-Uwe Bux

questions

unread,
Oct 29, 2008, 2:12:27 AM10/29/08
to

thanks

questions

unread,
Oct 29, 2008, 2:13:08 AM10/29/08
to
On 10月28日, 下午7时56分, Zeppe
> Zeppe- 隐藏被引用文字 -
>
> - 显示引用的文字 -

thanks

questions

unread,
Oct 29, 2008, 2:14:17 AM10/29/08
to

thanks

0 new messages