what's wrong?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • questions

    what's wrong?

    # 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

    #2
    Re: what's wrong?

    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

    Comment

    • Zeppe

      #3
      Re: what's wrong?

      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

      Comment

      • Juha Nieminen

        #4
        Re: what's wrong?

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

        Comment

        • Kai-Uwe Bux

          #5
          Re: what's wrong?

          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

          Comment

          • Sjouke Burry

            #6
            Re: what's wrong?

            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

            Comment

            • Juha Nieminen

              #7
              Re: what's wrong?

              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.

              Comment

              • Kai-Uwe Bux

                #8
                Re: what's wrong?

                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

                Comment

                • questions

                  #9
                  Re: what's wrong?

                  On 10ÔÂ28ÈÕ, ÏÂÎç7ʱ49·Ö, Kai-Uwe Bux <jkherci...@gmx .netwrote:
                  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

                  Comment

                  • questions

                    #10
                    Re: what's wrong?

                    On 10ÔÂ28ÈÕ, ÏÂÎç7ʱ56·Ö, Zeppe
                    <ze...@remove.a ll.this.long.co mment.yahoo.itw rote:
                    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

                    Comment

                    • questions

                      #11
                      Re: what's wrong?

                      On 10ÔÂ29ÈÕ, ÉÏÎç7ʱ18·Ö, Kai-Uwe Bux <jkherci...@gmx .netwrote:
                      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

                      Comment

                      Working...