[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

what's wrong?

questions

10/28/2008 11:22:00 AM

# 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?
10 Answers

Kai-Uwe Bux

10/28/2008 11:49:00 AM

0

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

10/28/2008 11:56:00 AM

0

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);
>
> 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

Juha Nieminen

10/28/2008 5:54:00 PM

0

questions wrote:
> y=x%pow(10,3);

What's wrong with 1000?

Kai-Uwe Bux

10/28/2008 6:22:00 PM

0

Juha Nieminen wrote:

> questions wrote:
>> y=x%pow(10,3);
>
> What's wrong with 1000?

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


Best

Kai-Uwe Bux

Sjouke Burry

10/28/2008 7:38:00 PM

0

Kai-Uwe Bux wrote:
> Juha Nieminen wrote:
>
>> questions wrote:
>>> y=x%pow(10,3);
>> What's wrong with 1000?
>
> 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

Juha Nieminen

10/28/2008 10:56:00 PM

0

Kai-Uwe Bux wrote:
> Juha Nieminen wrote:
>
>> questions wrote:
>>> y=x%pow(10,3);
>> What's wrong with 1000?
>
> Nit: 1000 does not occur in the above whereas 1000.0 does occur.

But 1000 would work, whereas 1000.0 wouldn't.

Kai-Uwe Bux

10/28/2008 11:18:00 PM

0

Juha Nieminen wrote:

> Kai-Uwe Bux wrote:
>> Juha Nieminen wrote:
>>
>>> questions wrote:
>>>> y=x%pow(10,3);
>>> What's wrong with 1000?
>>
>> Nit: 1000 does not occur in the above whereas 1000.0 does occur.
>
> 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

questions

10/29/2008 6:12:00 AM

0

On 10?28?, ??7?49?, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
> 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

thanks

questions

10/29/2008 6:13:00 AM

0

On 10?28?, ??7?56?, Zeppe
<ze...@remove.all.this.long.comment.yahoo.it> wrote:
> 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);
>
> > 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- ??????? -
>
> - ??????? -

thanks

questions

10/29/2008 6:14:00 AM

0

On 10?29?, ??7?18?, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
> Juha Nieminen wrote:
> > Kai-Uwe Bux wrote:
> >> Juha Nieminen wrote:
>
> >>> questions wrote:
> >>>> y=x%pow(10,3);
> >>> What's wrong with 1000?
>
> >> Nit: 1000 does not occur in the above whereas 1000.0 does occur.
>
> > 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

thanks