first attempt

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

    #1

    first attempt

    is this a valid algorithm for the question above? because I'm getting
    these errors:

    c:\\TempConvert er.cpp(28): error C2106: '=' : left operand must be
    l-value

    c:\\TempConvert er.cpp(29): error C2059: syntax error : '<'


    int roundUp( int )
    {
    int x, y, z ;

    x % 10 = y;
    if( y >= 1 && < 10 )
    {
    z = ( 10 - y ) + x;
    }

    return z;
    }
    *---------------------------------*
    Posted at: http://www.GroupSrv.com
    Check: http://www.HotCodecs.com
    *---------------------------------*

    Posted Via Usenet.com Premium Usenet Newsgroup Services
    ----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
    ----------------------------------------------------------
    Best Usenet Service Providers 2026 ranked by Newsgroup Access Newsservers, Usenet Search, Features & Free Trial. Add VPN for privacy.

  • anonymous

    #2
    Re: first attempt

    slickn_sly wrote:[color=blue]
    > is this a valid algorithm for the question above? because I'm getting
    > these errors:
    >
    > c:\\TempConvert er.cpp(28): error C2106: '=' : left operand must be
    > l-value
    >
    > c:\\TempConvert er.cpp(29): error C2059: syntax error : '<'
    >
    >
    > int roundUp( int )
    > {
    > int x, y, z ;
    >
    > x % 10 = y;
    > if( y >= 1 && < 10 )
    > {
    > z = ( 10 - y ) + x;
    > }
    >
    > return z;
    > }
    > *---------------------------------*
    > Posted at: http://www.GroupSrv.com
    > Check: http://www.HotCodecs.com
    > *---------------------------------*
    >
    > Posted Via Usenet.com Premium Usenet Newsgroup Services
    > ----------------------------------------------------------
    > ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
    > ----------------------------------------------------------
    > http://www.usenet.com[/color]
    You have numerous errors:

    Say x % 10 evaluates to 10. Then youu have 10 = y, which is illegal and
    illogical.
    What you want is something like y = x % 10;
    The if statement is not correct either:

    if anything it should be if (y >= 1 && y < 10) {}

    See the second 'y' in there?

    Now to the method signature. You want to pass in an int, but you
    probably also want to use the int inside the method, so you would do
    something like this:

    int roundUp( int passedToMethod )

    I am not sure, of course, what you want to do with it, since none of
    your local variables (x, y, and z) seem to use the passed value.

    Here is what I 'think' you want:

    int roundUp( int y )
    {
    int x, z;

    x = y % 10;
    if( y >= 1 && x < 10 )
    {
    z = ( 10 - y ) + x;
    }

    return z;
    }

    But I really have no idea, of course.

    Java is not a language where you can use everyday English to make it do
    what you want. It has its own grammar.

    Comment

    • Norm Mann

      #3
      Re: first attempt


      "slickn_sly " <bng_s@hotmai l-dot-com.no-spam.invalid> wrote in message
      news:41fb4a63_5 @127.0.0.1...[color=blue]
      > is this a valid algorithm for the question above? because I'm getting
      > these errors:
      >
      > c:\\TempConvert er.cpp(28): error C2106: '=' : left operand must be
      > l-value
      >
      > c:\\TempConvert er.cpp(29): error C2059: syntax error : '<'
      >
      >
      > int roundUp( int )
      > {
      > int x, y, z ;
      >
      > x % 10 = y;
      > if( y >= 1 && < 10 )
      > {
      > z = ( 10 - y ) + x;
      > }
      >
      > return z;
      > }[/color]

      Besides the hints that 'anonymous' gave you, that ".cpp" extention on
      "TempConverter. cpp" seems to indicate that you are using a C++ compiler, not
      JAVA. That means that you are either in the wrong newsgroup or using the
      wrong compiler.
      Your primary problem is you are trying to write a program without doing any
      evaluation of the task or how you wish to accomplish it. I can see some
      inkling of what you are trying to do, but your inexperience with the
      language is making this way too complicated.

      Your algorithum:

      input the number.
      get the result of a modulo 10 divide of the number.
      if the result is not zero, (or, in other words, if greater than zero, for
      the modulo division will limit the maximum value to 9.) then subtract the
      result from 10 and add that to the number.
      return the (modified) number.

      If you look at this, you'll see that you're only using two variables, the
      one which is input to the function and the result of the modulo divide and
      only one comparision is needed. If you are wondering about only two
      variables, remember that A=A+B only works in algebra only if B=0, but it's
      fine in computer programming because it means to replace the value in A with
      the result of A+B.

      HTH

      NM



      Comment

      • Hal Rosser

        #4
        Re: first attempt


        "slickn_sly " <bng_s@hotmai l-dot-com.no-spam.invalid> wrote in message
        news:41fb4a63_5 @127.0.0.1...[color=blue]
        > is this a valid algorithm for the question above? because I'm getting
        > these errors:
        >
        > c:\\TempConvert er.cpp(28): error C2106: '=' : left operand must be
        > l-value[/color]
        ==============
        You're putting c++ errors on a java newsgroup
        =============== =============== ===


        [color=blue]
        >
        > c:\\TempConvert er.cpp(29): error C2059: syntax error : '<'
        >
        >
        > int roundUp( int )
        > {
        > int x, y, z ;
        >
        > x % 10 = y;
        > if( y >= 1 && < 10 )
        > {
        > z = ( 10 - y ) + x;
        > }
        >
        > return z;
        > }
        > *---------------------------------*
        > Posted at: http://www.GroupSrv.com
        > Check: http://www.HotCodecs.com
        > *---------------------------------*
        >
        > Posted Via Usenet.com Premium Usenet Newsgroup Services
        > ----------------------------------------------------------
        > ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
        > ----------------------------------------------------------
        > http://www.usenet.com[/color]


        Comment

        Working...